Hi Michael,

This is not such an easy feature to implement, though as Daniel says, 
it's feasible with some caveats.  One issue to be aware of is 
performance-related -- PDF is very heavy to embed on a page because the 
format is very complex and poppler is therefore slow, so I'm not sure 
how responsive things will be if someone tries to insert lots of PDF 
fragments onto the page.  Also, we'll have to say goodbye to the legacy 
PDF export.

Roughly, the plan of action to do this and the surrounding changes 
needed / warranted in connection to it might look as follows.

The biggest structural change is modifying the xournal/poppler 
interaction so that there can be several PDF files being rendered for a 
single xournal document -- currently xournal maintains the unique PDF 
file being annotated in memory as well as bitmap renderings of the pages 
that have been accessed so far at the display resolution (in the "bgpdf" 
structure), calling poppler in background as needed to refresh when a 
page not yet seen becomes visible or when the display zoom level 
changes.  There's some soul-searching to be done to figure out the best 
data structures to maintain a working relationship with several poppler 
documents at once (presumably we just want to have multiple struct 
BgPdf's around, one for each file referenced in the xoj; don't let the 
"Bg" part of the name fool you, the BgPdf structure is not particularly 
specific to page backgrounds, it just keeps track of a subset of pages 
from a PDF document to be rendered through poppler into xournal's data 
structures as gdk-pixbufs to be inserted into the GnomeCanvas for 
display, and queues requests for re-rendering the pages at different 
resolutions).

(Right now the updating of PDF background pages is done via calls to 
rescale_bg_pixmaps() which in turns calls add_bgpdf_request() to 
schedule a PDF rendering; bgpdf_scheduler_callback() actually does the 
job.  One would presumably add other calls to add_bgpdf_request() to 
request updates to other embedded PDF pieces).

All that said, there are many moving pieces -- besides extending the 
internal data structures to allow several PDFs at once + PDF fragments 
that sit on the page rather than serve as background, one needs to take 
care of various things:

* extend the xoj file format, and the struct Item data structure, to be 
able to include not just png images but also pdf pages onto the xoj page.

* allow either embedding or linking to an external file (both for 
backgrounds and for objects sitting on the page, for consistency, though 
perhaps we'd hardcode a default behavior in the UI, e.g. embed pngs 
since they can be copy-pasted into xournal and not necessarily exist as 
pages, vs. link pdfs since we'd always receive those via a file 
selection dialog box and not a copy-paste of a bitmap fragment, though 
one could add a "embed/link" pair of radio buttons to the file selection 
box).

* not sure if this is something you need, but perhaps allow some method 
to 'crop' to an excerpt of a pdf page when a pdf object placed on the 
page gets resized, rather than rescaling it and keeping the whole pdf 
page. If we're going to display PDF bits and pieces, might as well allow 
the user to display only *part* of a PDF page, eg so they don't have to 
figure out how to modify the bounding-box of the PDF page on the other 
end of things (ever tried to produce "bounding box sized" rather than 
"printer page sized" PDFs from random office software?).

* regarding rescaling, one needs to be aware that poppler can only 
render to bitmaps with a same scaling ratio for x and y directions, so 
we can't easily allow rescalings of PDF fragments that modify aspect 
ratio -- or rather, we could but they'll become blurry. The other option 
is to treat them like the text boxes and always rescale in an 
aspect-preserving manner.

* allow the page backgrounds for different pages to reference more than 
one PDF file -- if we're allowing fragments of various PDF files to sit 
on the page then we might as well allow a xoj file to annotate 
backgrounds taken from more than one PDF.

* kill the "legacy export to PDF" feature, which can't handle multiple 
incoming PDF files. (Or use it only when only one PDF is used as 
backgrounds and there are no on-page PDF fragments). (There are still 
some PDF files where it produces a better result than the new export to 
PDF via poppler).

* ideally, design a piece of UI to allow the user to modify what PDF 
page is being referenced somewhere -- e.g. modify the background of the 
current page to say "use instead page 46 of this other PDF file".  For 
fragments on the page this is not so crucial (one can always expect the 
user to delete the item and insert a new one) but for the background we 
currently lack any kind of decent user interface for changing what PDF 
page one wants to use.

(Conceptually perhaps the right thing to do is to make the PDF 
background behave just as an inserted PDF fragment, simply it lives on 
the Background layer instead of on a normal drawable layer, and always 
occupies the whole page when it is present; but we could want to rescale 
/ crop it or change what it is just as with the PDF items that Michael 
wants to put on the other layers).

I'm probably forgetting some other stuff too.

Anyway: I realize doing all this is just a very large undertaking and 
not realistic. I'm not suggesting either of you try to do all this or 
even the bulk of it. On the other hand, modifying the code to have 
multiple BgPdf structures and allowing pdf objects on the page (more 
specifically, just pasting the whole page 1 of a PDF at unit scale onto 
the xoj page) (perhaps working within the "Image" tool, but when the 
user selects a PDF instead of a bitmap format) might be a reasonable goal.

Best,
Denis

On 12/14/2015 06:05 AM, Michael J Gruber wrote:
> Hi there,
>
> I'm wondering what the current state is regarding inclusion of PDFs, and
> what the best direction would be. As far as I understand:
>
> - Xournal can annotate PDFs directly or load them as background. In each
> case, the page size is set to the PDFs page size. If you change it then
> the PDF gets rescaled. Also, this means one PDF per page, obviously.
>
> - Xournal can insert an arbitrary number of images and rescale them.
> They get embedded into the xoj.
>
> That get's you only so far if you want to include, say, multiple graphs
> into your lecture notes. I can convert PDF to PNG, of course, but that
> seems to be moot if Xournal knows how to render PDFs (using poppler),
> and besides the unnecessary increase in file size (embedded PNG), this
> also makes it difficult to update an xoj with updated graphs.
>
> So, ideally I would like to "include" PDFs as links to the PDF (just
> like the annotated PDFs), multiple ones per xoj page. I don't mind
> editing an xoj by hand (vim to the rescue...).
>
> Michael
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Xournal-devel mailing list
> Xournal-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/xournal-devel
>

-- 
Denis Auroux
UC Berkeley, Department of Mathematics
817 Evans Hall, Berkeley CA 94720-3840, USA
aur...@math.berkeley.edu

------------------------------------------------------------------------------
_______________________________________________
Xournal-devel mailing list
Xournal-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xournal-devel

Reply via email to