Quantcast
Channel: Change color in finished pdf file - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by Heiko Oberdiek for Change color in finished pdf file

$
0
0

Easy case with uncolored PDF and pdfTeX (unhappily very seldom):

The PDF file contains some drawings without explicit color settings andthe image will be included by the pdftex driver of the graphics package.

The following file generates such an image:

\documentclass{article}\usepackage[active,tightpage,floats]{preview}\begin{document}\begin{figure}\Huge\bfseries\sffamily\setlength{\fboxrule}{2pt}\fbox{Hello World}\end{figure}\end{document}

enter image description here

The following file includes the image (t.pdf) and changes its colors.

\documentclass{article}\usepackage{color}\usepackage{graphicx}\pagecolor{black}\color{white}\begin{document}\Huge\bfseries\noindentSome text.\\\includegraphics{t.pdf}\\Some text.\\\textcolor{yellow}{\includegraphics{t.pdf}}\\Some text.\end{document}

enter image description here

This trick does not work with other drivers, because the other driversnormalize the color before the image is included. If pdftex.def is giventhe option resetcolor then the color is set to \normalcolor duringimage inclusion.

Manual color fixes

With some knowledge of the internals structures the PDF file can be fixedmanually. First the compressed page contents needs to be uncompresed, e.g.:

pdftk test.pdf cat output test-uncompress.pdf uncompress

Then the pages content streams need to be identified and the color operationscan be either changed or deleted (by overwriting with spaces). Best is not tochange the size of the object otherwise the file offsets of the objects inthe xref table needs to be updated. BTW, also PDF (or PS) use % as comment char.Then the file can be recompressed.

Or the PDF file is converted to PostScript (e.g. with pstopdf from xpdf). Editingis easier if changing the file size does not matter.PostScript does not have a xref table. However, the detection ofthe color operators can be more difficult, because often they are renamed orhidden in procedures. Unlike PDF, PostScript is a programming language.

Programs for processing vector images like Inkscape

If the PDF file can be successfully imported in Inkscape or similar programs,the colors could be changed there.

Bitmap conversion

As last resort the image can be converted to a bitmap image (ghostscript and other convertes). That means qualityloss because of pixel data. But many image processing programs should be ableto change the colors.

Generating inverse colors can even be done by a feature of the PDF format thatis supported by pdftex.def. Colors can be inverted via the /Decode array (exceptimages with indexed color spaces). Eachcolor component has then two float values inbetween 0 and 1.Thus the number of color components must be known (Mono: 1, RGB: 3, CMYK: 4)

\includegraphics[decodearray=1 0 1 0 1 0]{rgbimage.png}

For example, the ghostscript device png16m can be used to generate PNGs forthis usage. More details are explained in the PDF reference. The options ofpdftex.def are shortly explained in the file itself.


Viewing all articles
Browse latest Browse all 3

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>