2

I have PDF file like this https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf which has one item defined in the bookmarks section (or Outline)

dummy pdf file

What I want to do is to prepend this file with page labeled "Table of contents" which would contain link to Dummy PDF File roughly like this

enter image description here

please note the outline can get very long and spanning multiple pages. So far I was able to read the outline from existing document when opening it with PdfReader.Open(document, PdfDocumentOpenMode.Import); and than reading property Outline

than with MigraDoc I'm able to create new document which renders Table of Contents and then joins those two documents together, but the links are not there and I'm not sure how to change my approach to be able to add them.

I also saw this but was not able to use it (I would like to use Migradoc for generating TOC) Add MigraDoc Table of Contents to PDFsharp PDF

Any ideas how I should adjust my approach?

vmachacek
  • 530
  • 1
  • 11
  • 27

1 Answers1

1

If you want to do the whole job with MigraDoc, then create the TOC with MigraDoc (as you already do), then add pages with MigraDoc and use AddImage to draw the contents of the imported PDF pages onto the newly created MigraDoc pages.

Bookmarks will be newly created from the MigraDoc properties.

It is possible to use AddImage to fill the whole page, not just the body of the page.

  • would you know how to make each page size exactly as one I'm importing? Because it might be so some PDF files have different sizes and on same-sized document that would look weird – vmachacek Sep 21 '22 at 16:40
  • 1
    With MigraDoc you can set the size of each page as you need it - this can be the size of the page you are importing. And you can draw the imported PDF page in any size you want - you can scale them to the size of the MigraDoc pages if sizes are different. You can set Width and/or height for the `Image` object returned by `AddImage`. – I liked the old Stack Overflow Sep 21 '22 at 18:21
  • 1
    here gist.github.com/vmachacek/7e13fc9c41e8ef189aef815ee200e83c is how my solution looks in the end. It takes reference on WPF which is okay in my case but less than ideal for most applications.. – vmachacek Dec 30 '22 at 18:09