Recently we found Paul Madary's blog post about digital signatures in a Univeral Application (UWP) with iText 7, and we wanted to share it. Paul gracefully agreed to let us do that, and as a bonus we upgraded the code to be usable out-of-the-box with iText 7.1.3. The only change needed is the method SignDocumentSignature.

A big thank you to our Q3 top contributors!

There are so many people that contribute information to us in order to help improve our code, products and projects. We want to make sure that our top contributors are being recognized for the help they give and that they know how much we appreciate them.

Top menu

Breadcrumb

How to attach files to a PDF?

I am struggling with attaching files to a PDF that I am generating at runtime.

6th November 2015

admin-marketing

I manage to attach a file to the PDF, but I can't seem to reference them as links within the PDF.

iText in Action suggests I can do this as annotations or document level attachments. I don't find the book easy to follow or the code easy to understand though. There also seems to be scarce help on this around in the way of articles on the internet but apologies if I have missed anything.

You can use this action for an annotation, a Chunk, etc... For instance:

Chunk chunk = new Chunk(" (see info)");
chunk.SetAction(action);

It is a common misconception to think that this will work for any attachment. However, ISO-32000-1 is very clear about the GotoE(mbedded) functionality:

12.6.4.4 Embedded Go-To Actions An embedded go-to action (PDF 1.6) is similar to a remote go-to action but allows jumping to or from a PDF file that is embedded in another PDF file (see 7.11.4, "Embedded File Streams").

If you meant to ask "I want to attach any file (such as a Docx, jpg,... file) to my PDF and add an action to the PDF that opens such a file upon clicking a link," then you're asking something that isn't supported in the PDF specification.

Feel free to read ISO-32000-1. If you didn't understand my book, you'll have to do an extra effort trying to read the PDF standard...

How to load a PDF from a stream and add a file attachment?

admin-marketing

When I save stream to file, the resulting PDF is not correct. The file attachment will always be an XML file, which I need to create in memory and never will be in file system. How can I do this with iText?

How to open an MS Word attachment by clicking an image?

Ready to use iText?

As always, if you have any technical questions, you can contact support with your valid support subscription or head over to one of our community support pages on Stack Overflow to see if your question has already been answered for our AGPL users.