GeneralPdflatex: how to insert arbitrary PDF code (img interpolate)

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
sdaau
Posts: 26
Joined: Fri Feb 19, 2010 2:08 pm

Pdflatex: how to insert arbitrary PDF code (img interpolate)

Post by sdaau »

Hi all,

Here is a MWE:

Code: Select all

% test.tex
\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=0.5\linewidth]{../img/mytest.png}
\end{document}
where the .png is, say, a screenshot showing text...

When I compile this with `pdflatex test.tex`, and open the resulting pdf file in `evince`, if I zoom in to the picture I can see the individual pixels enlarged - i.e., there is no smoothing/anti-aliasing.

So, I looked about this a bit, and found this post:
Bug #199916 in poppler (Ubuntu): “evince interpolates image by mistake”:
https://bugs.launchpad.net/ubuntu/+source/poppler/+bug/199916 wrote: evince ... shows images interpolated, if the pdf does not say "/Interpolate true".
If the pdf not says "/Interpolate true", evince should show the image not interpolated.
... and then I realized, that this 'anti-aliasing' of images that I want is probably due to a PDF command; so I tried to insert a "/Interpolate true" command in the PDF:

Code: Select all

$ sed -i 's!/Filter/FlateDecode!/Filter/FlateDecode\n/Interpolate true!' test.pdf 
and good enough - now, whether normal size, zoomed in or zoomed out, the PNG in the pdf is shown with anti-alias/smoothing; so it looks the way I want it.

So, I was trying to see whether there is an option to set interpolation for images in relation to `pdflatex` or `hypersetup`, couldn't find anything.

Finally, I thought, if there isn't some option for that, maybe the easiest would be to write directly to the pdf file from latex; I found references to `\pdfcatalog` in "[pdftex] options of \hypersetup{pdfpagemode=PageWdth}", and `pdfobj` in "Getting braces into \pdfobj, for a Document-level JavaScript. HOW?". ...

However, the problem is that apparently one would need to insert that PDF command in the "middle" of an `\includegraphics` - I tried the following:

Code: Select all

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\begin{document}

\includegraphics[width=0.5\linewidth]%
% \immediate\pdfobj{/Interpolate true} % crashes w: "Error: File `\immediate .png' not found."
{../img/mytest.png}

\immediate\pdfobj{/Interpolate true} % compiles here, but ends up on top of .pdf file as separate object; no effect on image
\end{document}
... and as it can be seen from the comments therein, no success..

So, does anyone have an idea how can I persuade pdflatex to interpolate (smooth) the images??

Thanks in advance,

Cheers!

PS, off-topic: I wander why the subject length in the is so conservative? I would have gladly written the title as "Pdflatex: how to insert arbitrary PDF code (image interpolation)", but there wasn't enough space :)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

sdaau
Posts: 26
Joined: Fri Feb 19, 2010 2:08 pm

Pdflatex: how to insert arbitrary PDF code (img interpolate)

Post by sdaau »

Just a brief update - I looked into the pdftex users manual http://sarovar.org/docman/view.php/106/66/pdftex-s.pdf; and found:
http://sarovar.org/docman/view.php/106/66/pdftex-s.pdf wrote: Literals and specials
\pdfliteral [ pdfliteral spec ] general text
Like \special in normal TEX, this command inserts raw pdf code into the output.
... and generating an image with:

Code: Select all

convert -size 150x150 xc:white -pointsize 24 -draw "text 25,60 'test'" test.png
and using the following test.tex code:

Code: Select all

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\begin{document}

\pdfliteral direct {/Interpolate true}
\special {pdf:direct: /Interpolate true }
\includegraphics[width=0.5\linewidth]{mytest.png}
\pdfliteral{/Interpolate true}

\end{document}
... unfortunately results with no '/Interpolate true' being inserted anywhere:

Code: Select all

$ pdflatex test.tex
...
Output written on test.pdf (1 page, 10253 bytes).
Transcript written on test.log.
$ grep -ai 'int' test.pdf
$
... so it's still an open issue, this inserting of raw PDF :)

Cheers!
Post Reply