1

I have successfully parsed a XML file into a XHTML file, and then finally into a PDF using iText.

Now the next achievement would be to attach and link the Base64 embedded documents from the XML file into the PDF document. Attaching these files (so they appear in the "attachments pane" in the PDF viewer) is working.

Now my problem is that these attachments (.doc, .ppt, etc) should be opened by clicking on a text link or an image (icon). The images (and document names e.g. "test.doc") are already in the PDF, but how can I link the right file to the right image or text link? Could some of you give me a hint where to start?

JNYRanger
  • 6,829
  • 12
  • 53
  • 81
Pali
  • 1,337
  • 1
  • 14
  • 40
  • Could you please provide a link example? – user Jun 22 '15 at 13:11
  • @ConstantineNovykov by "link" i mean something like a hyperlink or a simple html href link. I dont know how such "links" look like in PDF? or do you mean something else? – Pali Jun 22 '15 at 13:13
  • Posted an answer. Please, look below. – user Jun 22 '15 at 13:16
  • @ConstantineNovykov okay this seems logical but do also have an example for me? because I have no idea how I can do those mapping with "endpoints" and "hyperlinks". Can this all be done with the iText API? – Pali Jun 22 '15 at 13:19
  • Edited. Please tell if you have any more questions. – user Jun 22 '15 at 13:21

1 Answers1

2

What you could do is create a "mapping" of those files to the names, so they will have a unique identifier. After that you just create an endpoint that will return required file with required mime type (check out Octet stream as well). In the PDF you just add the hyperlinks that will go to your endpoint and fetch the required document by name.

EDIT: You could actually have more than one endpoint: you could need one for every mime type you use for more convenience.

In order to create a link inside PDF, use Anchor from iText lib.

In order to create an endpoint - it is really up to you. You can use any way to create a webapp that would return a file from web interactively.

user
  • 3,058
  • 23
  • 45
  • This seems ecaxtly what I was looking for, but one question: this example creates a pdf from scratch, but I already have the pdf (and the xhtml file) so how can create an Anchor() of the already existing text "test.doc" which should open the attachment "test.doc" ? – Pali Jun 22 '15 at 13:26
  • You could "get" the document, find the place by parsing it and insert the Anchors manually. I.e. you don't create a "new" paragraph, you find one you already have. – user Jun 22 '15 at 13:45
  • so how can I find one? there is no method like `getParagraph()`? – Pali Jun 22 '15 at 14:09
  • 1
    http://stackoverflow.com/questions/19066141/itext-get-field-coordinates-from-existing-pdf – user Jun 23 '15 at 09:25