I am trying to generate PDF/A-1 compliant documents, in which transparency is not allowed. I would like to check, if included PDF and PNG images have transparency.

Is there a TeX way to check this? Otherwise, what is the proper way to change the \includegraphics command to call external tools to check this?

Edit: External tools for checking transparency:

For PNGs, ImageMagik's identify does the job nicely. It displays [s]rgba when there is an alpha channel (otherwise it's rgb):

# identify -format '%[channels]' Transparent.png 

Even better:

# identify -format %A Transparent.png 

For PDFs, this is more complicated (see eg here): There are as graphical style attributes fill opacity (/ca) or stroke opacities (/CA) below a value of 1.0, or there is a soft mask (\SMask), or there is a transparency page group defined (/S /Transparency). grep expression:

grep -aE -e '/[Cc][Aa] +0?\.[0-9]' -e '/SMask' -e '/S /Transparency' *.pdf

I bet it is somehow possible to check with gs, but I did not find it so far.

  • For png, I think that file gives you this information. Doesn't it output RGB for non-transparent and RGBA for transparent? Or I'm sure convert can give you this information if you go through its (many) options! – cfr Jan 8 '14 at 0:37
  • A tip: You can use backticks ` to mark your inline code as I did in my edit. – Tobi Jan 8 '14 at 1:05
  • Tobi: I'll do that. cfr: Thanks for the comment, identify does the job. – Florian Bw Jan 8 '14 at 20:43
  • To my knowledge there is no "Tex way" to check graphics. That is, during compilation of the document, it does not look into the image code to tell whether a partiular image has transparency, or RGB or CMYK, has a color profile, or anything like that. External programs must be used in advance. It would be nice if Tex could invoke an external command-line program and be able to throw an error (in Tex) if the image is wrong, according to some crieteria. File that under "Wish List." – RobtA Jul 16 '15 at 1:31

I would use ghostscript to remove the transparency once the pdf is generated, using

gs -o converted.pdf -sDEVICE=pdfwrite -dHaveTransparency=false input_file.pdf

| improve this answer | |

If you are generating your pdf document from the tex document at the command line then any of the previous suggestions are viable. To decrease typing at the command line you can write a makefile to handle the transparency checks and then generate the pdf.

If you really want to do everything from within the tex document you can try the bashful package or the \write18 command as suggested here.

| improve this answer | |

There is no 'built in' way to check if an image is transparent. As such, you will need to pre-process your images either as part of the TeX run (using shell escape) or before it. Doing things during the TeX run is going to be more awkward here as it has to happen every time you do the rung and requires a lowering of your security settings. In any case, the appropriate tools for removing transparency are off-topic for us.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.