Menu

#69 unable to insert custom/external page into PDF

open
nobody
None
5
2021-02-05
2010-09-16
No

I'm not sure whether to call this a bug or a feature request, but it's a rather large bug or missing feature for my use case. Please reassign as appropriate.

Use case: I use Xournal for my class presentations. I need to update many of my lectures each semester, sometimes by adding a page, other times by removing a page. Often, I need to insert a slide into the middle of an already marked PDF document.

With version 0.4.5, this doesn't look possible. The best I can currently do is to insert a copy of the current page before or after the current page. What I actually want is to update the underlying PDF, and then insert a page equivalent in the xoj file. (My example workflow below might better elucidate the issue I'm trying to describe.)

Ideally, what I would like to do is to be able to insert a new page in the underlying PDF, and for Xournal to recognize that it's page count is off when I try to insert a page. Then it could add the new page (or pages) by simply realigning it's internal notion of to which page number each xoj page XML element is attached.

I can currently work around this by the fact that I'm savvy, but it's rather tedious. Here's my current workflow via an example:

1. Create simple 4 page PDF with obviously different pages.

2. Open Xournal and mark up pages 1, 2 and 4 (or whatever)
with scribble. (Just to make the point).

3. Insert a page before 2.

3. Save the xoj file.

4. Close Xournal.

5. Insert a new page as page 2 in the underlying PDF. (The
updated PDF should now have 5 pages.)

If you open Xournal at this point, you'll note that the page you inserted is duplicated as page 2 and 3, and that the final page (what is now page 5 in the underlying PDF) is not shown.

6. $ gunzip < file.pdf.xoj > file.xoj.tmp

7. Edit the uncompressed xoj.tmp file. Note that the XML file describes
the new page as a duplicate of the page before which you inserted
a new page, via the XML background element attribute 'pageno'. The
pageno will be the same number as the one after it. In this case, 2.

8. Edit the second pageno attribute to be the previous number +1. Do
this for all the rest of the pages, so that the xoj file will point
the overlay pages at the correct underlying PDF pages.

9. Save, and rezip the file: $ gzip < file.xoj.tmp > file.pdf.xoj

10. Open up Xournal, and now finally note the inserted page.

I will attach two XOJ files to highlight what the above workflow changes.

(Excellent piece of software, btw. You've really thought through a bunch of use-cases, and the polish is very nice. I keep thinking "Wouldn't it be cool if ..." and sure enough, you've done it.)

Discussion

  • Kevin Hunter Kesling

    Two copies of a file, one the result of going through my workflow.

     
  • Denis Auroux

    Denis Auroux - 2010-09-17

    Good point. Automatically "realigning" PDF page numbers when you create a new PDF page in the middle of the PDF file is pretty hard, because there's no easy way to know which page is the new one (all that can be decided easily is that the PDF file has more pages, but how does one know which new page corresponds to which old page?); and I'm not sure how to come up with an intuitive user interface for the general case.

    What however I agree should be added to the user interface is:
    - when used on a page with a PDF background, the "new page before" / "new page after" commands should prompt for whether the new page should be with the same PDF background, with a different page of the PDF file, or just plain paper.
    - in the Journal -> Paper style menu, there should be an option to set a different page of the pdf file than the one currently assigned to the given page of the journal.

    Ah, I'm suddenly figuring out that maybe you never have duplicate pages (two xoj pages annotating the same PDF page), nor plain paper pages in between PDF pages -- perhaps you expect a 1-to-1 correspondence between PDF pages and xoj pages. I'm not sure how to make it intuitive, but I guess one could have a "realign PDF" command that makes page 1 of the xoj file annotate page 1 of the PDF, page 2 annotates page 2 of the PDF, and so on. Assuming you never insert duplicate pages or blank non-PDF pages, this would then fix things in your use case. But I'm still not sure if it would be intuitive for other users.

    Denis

     
  • Kevin Hunter Kesling

    You've offered some insight as to why ye of the clearly-thoughtful-developer breed hadn't already thought of my use-case, so please bear with me as I think through this.

    I initially have two thoughts:

    1. You're spot on with the needed menu additions ("new page before/after" prompt, new paper style option).

    I also think your solution is cleaner than my initial thought: it doesn't have to be intuitive if it's an innocuous feature, or one that we assume to be used very infrequently. (As in my case, I would have to go through this maybe 10 times a semester.)

    Since you currently assume that the xoj file marks up a single PDF, have a menu entry title "xoj to pdf alignment" (or something along those lines). Then when clicked, it either brings up a window (ick), or adds a temporary bottom bar to the main Xournal frame that has this text "XOJ page [x] attached to PDF page [y]". The [x] and [y] could be spin boxes.

    This doesn't make it particularly /easy/ to insert a page, as it means that every page after an insertion would have to be manually updated, but it at least makes it possible. (I'll bet we both agree that my gunzip/realign/gzip method is not acceptable for the general case. :-) )

    2. Have a "double" meta view, analogous to OpenOffice's Presentation (or Powerpoint's) slide interface. It could be either xoj slide centric, or PDF background centric. (I'll attach an xoj file with a visual mock up of what I'm currently envisioning.)

    For example, if you added a menu item under Journal titled "Manage Slides" or "Manage Pages", you could bring up a new window (again, ick) or some interface that would display each slide of markups (without a background), horizontally associated with the current background (without markup), and what the displayed output is. (I hope the attachment portrays this thought well enough.) Then, with some of your good UI sense, folks could insert a markup page on the left, which would automatically insert a /blank/ page on the right. Then, folks could change the background page as appropriate with perhaps a right-click menu or some other interface.

    Does thought 2 give you an idea of implementation?

    P.S. I *very* much appreciate your attention to detail, and work on this project. I'll briefly mention that if it wasn't for the quality of Xournal, I probably would not have made the jump to Linux just under a year ago.

     
  • Kevin Hunter Kesling

    Mockup of possible interface for associating xoj slides/pages with different PDF backgrounds

     
  • Kevin Hunter Kesling

    Oh, and you are correct, I *was* assuming a 1-to-1 ratio between xoj pages and PDF pages. Clearly, that is not a global assumption or use case.

     
  • Ragnarok

    Ragnarok - 2017-04-03

    Hi

    I just ran into the same problem described here by Kevin. I'm also using Xournal v0.4.8 built from source, to annotate Beamer slides, and found that inserting a slide in the middle of my presentation after having created an xoj file linking to it results in the last slide being unavailable for annotation within Xournal.

    As Kevin mentioned, I really do have to add and remove content to my slides, and the ability for Xournal to pick up new pages added to the linked pdf file would be great! It doesn't even matter if the annotations from the newly inserted slide until the last slide are out of sync by one page since I can just insert a blank space one page tall to fix it.

    Has this issue been resolved yet? I noticed this question was posted in 2010. Is there something I'm missing?

    Your help is much appreciated!

     
    • Denis Auroux

      Denis Auroux - 2017-04-04

      Hi, this feature request has not been addressed yet -- the only sensible
      way to fix things is to add a whole user interface to let the user
      reassign PDF pages to document pages in various ways (one page, in batch
      when all page numbers shift, etc.), and that's not so easy. In the
      meantime, Kevin's solution is indeed the best one -- you can add PDF
      pages by hand into the xournal file: zcat file.xoj > file2.xoj, open
      file2.xoj in your favorite text editor, make necessary changes. (No need
      to re-gzip at the end).

      To update page numbers, change the value of the "pageno" attribute in
      the lines that say
      <background type="pdf" pageno="..."/>

      To add a new page, just insert the code fragment

      <page width="..." height="..."> (same as your other pages, depends on
      page size in your PDF)
      <background type="pdf" pageno="..."/> (put the page number you need
      from the PDF)
      <layer></layer>
      </page>

      (or use xournal to add a new page before/after and then change the page
      number).
      Sorry there's still no user interface to do this within xournal.

      Denis

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

       
      • Ragnarok

        Ragnarok - 2017-04-04

        Hi Denis

        Thanks for your response. Your proposed workaround works!

        Just wondering if it might be possible/feasible to compare the total number of pages actually present in the linked PDF file, and the largest page number mentioned in the XOJ file, each time the XOJ file is opened. If there is a mismatch in the two, the following actions could be taken:

        • If the PDF file has fewer pages than the XOJ file, the annotations in the XOJ file's extra pages are placed on blank pages.
        • If the PDF file has more pages than the XOJ file, the extra PDF pages are just inserted as backgrounds with no annotations to the end of the XOJ file.

        If I'm not mistaken, I don't see any real need to maintain a one-to-one relation between PDF and XOJ pages, hence requiring no change to the GUI. For instance, if an extra page is added to the middle of the PDF file, the XOJ file is not aware of this and one-to-one correlation is lost anyway. This is not really an issue even, since as I mentioned before, I could just shift all annotations in the XOJ file down by one page to solve this problem. I could, similarly, move all annotations up by one page if I delete a page from the PDF file (I haven't tried this feature yet, but I'm assuming it would work if I'm viewing my PDF file in continuous mode).

        If I am not mistaken, and this is indeed the case, then the issue that Kevin and I have encountered is potentially more serious than maintaining one-to-one correlation between the PDF and XOJ files.

        Would love to hear your thoughts.

        Cheers

         

        Last edit: Ragnarok 2017-04-04
        • Denis Auroux

          Denis Auroux - 2017-04-04

          Copying xournal-devel since there's an actual UI proposal further down
          this message (in fact several -- as usual with me, there's the first
          idea, then the amended hopefully better idea). The question is how to
          adjust the xournal file to create/delete xoj pages when the PDF file it
          annotates changes in length, possibly by having pages inserted/deleted
          in the middle of it rather than at the end.

          On 04/04/2017 01:41 AM, Ragnarok wrote:

          Just wondering if it might be possible/feasible to compare the total
          number of pages actually present in the linked PDF file, and the largest
          page number mentioned in the XOJ file, each time the XOJ file is opened.
          If there is a mismatch in the two, the following actions could be taken:
          /If the PDF file has fewer pages than the XOJ file, the annotations in
          the XOJ file's extra pages are placed on blank pages.
          / If the PDF file has more pages than the XOJ file, the extra PDF pages
          are just inserted as backgrounds with no annotations to the end of the
          XOJ file.

          This is not a good idea in general, because many people (at least me)
          annotate PDF files but insert blank pages of "plain paper" for extra
          comments in between PDF pages wherever extra space is needed. So I might
          have a page of handwritten annotations between pages 3 and 4 of the PDF
          file, etc. etc.

          If I'm not mistaken, I don't see any real need to maintain a one-to-one
          relation between PDF and XOJ pages, hence requiring no change to the
          GUI. For instance, if an extra page is added to the middle of the PDF
          file, the XOJ file is not aware of this and one-to-one correlation is
          lost anyway.

          Indeed -- but then the GUI should help the user fix the correlation in
          the right way, because:

          This is not really an issue even, since as I mentioned
          before, I could just shift all annotations in the XOJ file down by one
          page to solve this problem.

          How do you propose to do this? There is no easy way to move a whole
          page, especially if
          there are several layers on it, and there is even less of a way to move
          a range of pages.

          I could, similarly, move all annotations up
          by one page if I delete a page from the PDF file (I haven't tried this
          feature yet, but I'm assuming it would work if I'm viewing my PDF file
          in continuous mode).

          No it doesn't -- sorry! Continuous is a viewing mode, doesn't change the
          behavior of the drawing tools which still work one layer at a time on
          one page
          at a time.

          So: the right thing to do is instead add an entry or two in the page
          menu. Most
          obviously, one that sets the background of the current page to be page
          <N> of the
          PDF for your favorite value of N. Then by using Page -> New Page
          After/Before
          and this new command, you can create the extra pages you need and assign
          them to
          the PDF pages you want. Second, there should be a bit of magic that
          figures when
          you are trying to adjust PDF page numbers and asks if you are trying to
          adjust all
          following page numbers as well.

          Initial thought: Perhaps the new commands should be

          • Page -> Paper style -> PDF page: sets background of current page to
            specified PDF page
          • Page -> Adjust PDF Pages After: asks for a number k of pages to shift
            by, if run on
            a xoj page that annotates page n of the PDF and k is positive then
            creates k new blank
            xoj pages that annotate pages n+1, ..., n+k of the PDF, and shifts all
            PDF pages greater
            than n in subsequent xoj pages by +k. If k is negative, then replaces
            backgrounds in
            subsequent xoj pages by blank background if page number is n+1, ...,
            n+|k|, and shifts
            PDF page numbers by k for page numbers greater than n+|k|.

          Example, if I'm currently having backgrounds in the xoj that are PDF pages
          1 2 3 blank 4 5 6 blank 7
          and on xoj page 5 = PDF page 4 I ask to adjust PDF pages after by 2,
          then it inserts two blank pages annotating pages 5 and 6, and the pages
          with backgrounds 5 6 blank 7 become 7 8 blank 9.
          Whereas if I ask to adjust by -2, then no xoj page disappears but the
          backgrounds become 1 2 3 blank 4 blank blank blank 5.

          Perhaps for simplicity there should also be Page -> Adjust PDF Pages at
          End (that does it at the end of the file).

          Revised thought, which I think is better: Instead of creating Page ->
          Adjust PDF Pages, this should be just built into Page -> New Page
          Before/After/At End, and Page -> Delete Page. Namely, when running a
          "new page" command when the current (or last) page is annotating a PDF,
          then New Page should ask the user whether the new page is blank, a
          duplicate of the current PDF page, or a new PDF page to insert by
          shifting all PDF page numbers by 1. And similarly Delete Page should ask
          whether to shift all remaining PDF page numbers by 1. This is probably
          much more intuitive than creating a new command "adjust PDF pages" --
          the user who wants to fix pages will probably try to add or remove pages
          in the xoj and might reasonably expect xournal to adjust the xoj/pdf
          page correspondence as this happens, so this is where we should ask.
          (One would still have Page -> Paper style -> PDF page to allow for
          manual adjustments whenever needed).

          Is this reasonable?

          Further thoughts for beyond phase 1:

          • As an additional bit of magic, "New page at End" could detect if the
            last PDF page used is less than the current PDF file page count and ask
            if you want to create all the missing pages at once if more than one.
            (Not going to happen in phase 1 of the plan, don't get your hopes up. I
            assume that doing things one page at a time will still be useful at
            first and should handle the most pressing needs).

          • Yet another issue is that xournal does not refresh when the PDF
            changes under its nose (even though printing/exporting might in some
            cases work with the PDF file on disk rather than the one shown on
            screen). Perhaps the File menu should contain an entry to refresh the
            PDF background. I don't know if this is easy to do though, I think it
            may be easier to just do the current thing and ask the user to save and
            re-open the xoj as a way to refresh the PDF. One could imagine however
            an automagic command that refreshes by saving (prompting the user of
            course), re-opening the xoj, and then detects if page count has
            increased in the PDF and offers to create new pages at end if needed. Or
            even better, perhaps we should monitor the PDF file for changes (not all
            the time, perhaps only after specific operations such as scrolling
            beyond a page or saving the file) and, if it has changed, prompt the
            user whether they want to save and re-open to refresh the PDF. What do
            you think?

          Denis

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

           
          • Ragnarok

            Ragnarok - 2017-04-08

            Hi Denis

            Thanks for your detailed response and proposal, and apologies for the delay from my end.

            I had clean forgot about the possibility of manually adding pages in between for annotations, mostly I guess, because I've never used this feature.

            I love your idea about incorporating the ability to sync with the PDF at the New Page and Delete Page point. This should definitely address the most pressing issues as you said. Also really like your ideas in the final two bullet points. Your explanations were really comprehensive and I can't think of anything I can add.

            Finally, I did try using a Vertical Space to push an annotation to the next page when viewing in continuous mode, and it did work, althought the annotations on successive pages did not get pushed to later pages as well. I assume is the expected behaviour though, which it would not make too much sense to modify. Also, as you mentioned, this would definitely not work if there were multiple layers as well.

            Reagan

             
  • Ragnarok

    Ragnarok - 2017-04-03

    I would also like to take this opportunity to sincerely thank you for your years of work developing this software. I frankly have no idea how I would have fit presentations into my workflow with Linux without this software. It would have meant resorting to Windows and Powerpoint, just the thought of which makes me shudder.

     
  • Emmanuel Favre-Nicolin

    This feature would be most interesting. I think I could achieve the insertion of pdf additional pages,in the case in which additional pages were added in the end of the pdf. When adding pages, in the actual version of xournal++, when using the option to add pdf with a pdf background, there is an option to select unused pdf pages. I added 2 new pages in a pdf and could include them inside the xournal file. Of course this not automatic but in my case it solved my "problem.

     

Log in to post a comment.