2

I've created a PDF/A-3 document with attached image files using iText 5.5.4. What I need is to add links in the body of the document to directly open the images.

I tried this to create the links :

PdfAnnotation linktoimg = PdfAnnotation.createFileAttachment
                                        (writer, rectangle, "Open picture", fileSpec);
writer.addAnnotation(linktoimg);

Compilation is OK but at run time I get a PdfAConformanceException :

Annotation type /FileAttachment not allowed

I also tried to add an anchor to open the images but I've found that ISO-32000-1 specification doesn't support it. And the gotoEmbedded functions only works for attached PDF files.

So is there a way to achieve this or am I facing a limitation with PDF/A?

Silas
  • 813
  • 1
  • 10
  • 18

1 Answers1

3

This is not a limitation of PDF/A-3 (or PDF/A-2). In fact, you have uncovered a bug in the iText PDF/A implementation. FileAttachment annotations are disallowed in PDF/A-1, but not in PDF/A-2 and PDF/A-3.

I have pushed a fix. It will be available in the develop branch of iText repository on GitHub soon. Alternatively, if you don't want to build from source, you can download a snapshot build from the iText repository

rhens
  • 4,791
  • 3
  • 22
  • 38
  • 2
    Keep in mind that while PDF/A-2 allows file attachments, any file embedded in the PDF/A-2 file needs to be a compliant PDF/A-2 file by itself. It's only with PDF/A-3 that you can embed arbitrary files (such as the image files the OP talks about). – David van Driessche Dec 06 '15 at 15:59
  • @rhens: You were right, the exception is gone when using the last snapshot version of iText. However the link doesn't open the image. I used the exact same code from [this page](http://stackoverflow.com/questions/31006683/itext-clickable-image-should-open-ms-word-attachment). You can get the obtained PDF [here](http://expirebox.com/download/ab5ccc3d265917c1e03dbd3d6584a2f3.html). I guess I'm missing something... – Silas Dec 07 '15 at 12:54
  • 1
    Your sample does work for me. If you open it in Acrobat or Reader, it will typically show a blue bar at the top, saying that file claims compliance with PDF/A. In that case, the viewer has disabled the annotation. If you click "Enable Editing" in that bar, or if you disable PDF/A View Mode (`Preferences`, `Documents`, `View documents in PDF/A mode`), the annotation will be active. Double clicking it will open the image. If you're using a different viewer, you should check if that viewer has (full) support for these annotations. – rhens Dec 07 '15 at 15:15
  • Gosh! It works indeed by enabling the editing feature... So if I understand this well, there is no way to have a link which opens an embedded picture in PDF/A mode ? – Silas Dec 07 '15 at 15:29
  • 1
    I don't think there's a viewer requirement ("confirming reader" in the PDF/A-3 spec), that puts restrictions on FileAttachment annotations. So looks like an implementation decision of Adobe to disable these annotations for PDF/A files (in PDF/A View Mode). – rhens Dec 08 '15 at 00:16
  • @DavidvanDriessche Yes, for PDF/A-2 embedded files need to be PDF/A-2 or PDF/A-1 compliant. iText does not check for PDF/A compliance when embedding a file, it's not a PDF/A validator. So there's some user responsibility here. The only that iText does check in this regard is the MIME type: an exception is thrown when it's not `application/pdf`. That should already prevent a lot of cases of unintended embedding of other file types. – rhens Dec 08 '15 at 00:26