[Ipe-discuss] PDF image import

Otfried Cheong otfried at ipe.airpost.net
Tue Mar 25 03:12:41 CET 2014



On 25/03/14 00:46, Frank Siegert wrote:
> But coming back to my original question of a *universal* PDF import
> tool: how are *raster* images currently embedded into the PDF output
> technically (via Latex' includegraphics?) and displayed on screen (via
> Qt's QImage?)?
> Would it be possible to do something similar for PDFs, i.e. include
> them in the PDF output through includegraphics and use poppler-qt's
> renderToImage[0] for displaying on screen?

PDF is a complex file format.  A PDF document consists of a number of 
objects, that are linked together as a directed graph.  Ipe handles this 
file format itself - it does not use pdflatex to create the output file 
(when I wrote Ipe 6, pdflatex was simply not powerful enough to do this 
- today this would be possible).

Inserting a raster image is easy:  Ipe reads the bitmap, packages it 
into a PDF object, includes this object in the PDF output, and 
references it from the page stream.

Including a PDF file is several orders of magnitude harder:  You can't 
just take the PDF file and insert it in your document.  You have to 
start with the contents stream that you want to include, and then figure 
out all its dependencies (objects referred, directly or indirectly, from 
it).   All these objects need to be copied into the PDF document for the 
inclusion to work.  This is how \includegraphics in pdflatex works - I 
helped work on that code many years ago, so it's certainly doable, but a 
sizeable project.

The Ipe rendering pipeline doesn't use Qt at all.  Qt is just a thin 
layer for the user interface, and can be easily replaced (and probably 
will sooner or later, for instance to make an Android port of Ipe); so 
poppler-Qt itself is not useful.   The poppler library itself has a 
cairo backend, so it should be possible to render a PDF page at the 
right scaling into the Ipe document.  Using poppler will not be 
straightforward, as we don't have a PDF document to work with, just a 
loose collection of PDF objects.  This opens a can of worms - using 
Poppler's internal structures makes Ipe depend on any changes in Poppler 
(and already updating pdftoipe when Poppler changes takes time). 
Poppler is a large library, and I'm hesitant to add such a dependency to 
Ipe.

I am currently experimenting with adding more complete support for the 
PDF operators in Ipe text objects.  In the end, I want to support pgf 
and tikz inside text objects as much as possible.  A lot of pgf and tikz 
functionality already works in the PDF output, as it's just linear PDF 
operators, but it's not yet displayed correctly on the screen.  I can 
already see that for more complicated tikz/pgf usage Ipe will have to 
copy resources of the PDF object into the output (as described above). 
When this is implented, using \includegraphics inside text objects to 
include a PDF document would work as well. However, it would not be able 
to display your plot correctly, because what pstricks does there is just 
too weird.  (The output PDF should be correct at that point.)

But don't hold your breath - getting that far will take a while.

Cheers,
  Otfried



More information about the Ipe-discuss mailing list