# Lossless \includegraphics for PNG without conversion for pdflatex/xelatex

I try to find a way to include raster graphics in pdflatex/xelatex without repacking/conversions/etc.

Accorging to "pdflatex that does not change the image data. This can be tested" (from "PNG and JPG quality loss inserting webpage screenshot into LaTeX document") this behaviour should be by default.

I tried to test it, see small project https://github.com/belonesox/xelatex-and-graphics-quality:

• `\includegraphics{lenna.png}` → xelatex/pdflatex → PDF → pdfimages → extracted.ppm
• compare lenna.png vs. extracted.ppm → diff.png

And for xelatex and pdflatex I see nonempty diff.png https://github.com/belonesox/xelatex-and-graphics-quality/blob/master/diff.png

Is it a bug or a feature?

Does it possible to include to PDF by xelatex raster PNG (or any other format) without repacking/conversion?

• png you are always going to have to do something as pdf doesn't have png images internally, for jpg you should be able to more or less include it as is with some wrapper (without answering your question about actually what happens with current engines) – David Carlisle Jan 25 '17 at 13:12
• Thank you, so assumption "pdflatex that does not change the image data. This can be tested" from [tex.stackexchange.com/questions/65059/… is not true. OK. – Stas Fomin Jan 30 '17 at 17:56
• No, I'd trust Heiko there, but what he says is not incompatible with what I wrote. png you are going to have to unpack and re-encode but as a lossless bitmap format that should all be reversible which is what Heiko showed. My comment was that for jpg you can directly include the jpg stream in a pdf – David Carlisle Jan 30 '17 at 18:42