13

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 
srgba

Even better:

# identify -format %A Transparent.png 
True

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.

4
  • 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, 2014 at 0:37
  • A tip: You can use backticks ` to mark your inline code as I did in my edit.
    – Tobi
    Jan 8, 2014 at 1:05
  • Tobi: I'll do that. cfr: Thanks for the comment, identify does the job.
    – Florian Bw
    Jan 8, 2014 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, 2015 at 1:31

3 Answers 3

3

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

1

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.

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .