PDF/A and LocalGoto not working

"Denzen, van Carl" <[email protected]> Mon, 22 Dec 2014 16:25:45 +0100
Newsgroups gmane.comp.java.lib.itext.general
Message-ID <[email protected]>
setLocalGoto doesn’t work when I create a PDF/A-1B document. When I change the document to ordinary pdf (the commented-out writer code), it works as expected.

I use iText 5.5.4.
My code is:
package nl.vandenzen.pdfa1b;

import com.itextpdf.text.Chapter;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ICC_Profile;
import com.itextpdf.text.pdf.PdfAConformanceLevel;
import com.itextpdf.text.pdf.PdfAWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
 * @author CDN
*/
public class PdfA {

       /**
       * @param args
       *            the command line arguments
       */
       public static void main(String[] args) {
             PdfA pdfA = new PdfA();
             try {
                    pdfA.test1();
             } catch (FileNotFoundException ex) {
                    Logger.getLogger(PdfA.class.getName()).log(Level.SEVERE, null, ex);
             } catch (DocumentException ex) {
                    Logger.getLogger(PdfA.class.getName()).log(Level.SEVERE, null, ex);
             } catch (IOException ex) {
                    Logger.getLogger(PdfA.class.getName()).log(Level.SEVERE, null, ex);
             }
       }

       void test1() throws FileNotFoundException, DocumentException, IOException {
             Document document;

             document = new Document();
             // Set conformance level to PDF/A-3B
             PdfAWriter writer = PdfAWriter.getInstance(document,
                          new FileOutputStream("./target/pdfa4-example.pdf"),
                          PdfAConformanceLevel.PDF_A_1B);

             /*
             * PdfWriter writer = PdfWriter.getInstance(document, new
             * FileOutputStream("./target/pdfa3-example.pdf"));
             */
             // XMP metadata is a PDF/A requirement. The XMP metadata is constructed
             // automatically from the document info.
             writer.createXmpMetadata();
             document.open();
             // Output intent is a PDF/A requirement.
             ICC_Profile icc = ICC_Profile
                          .getInstance(new FileInputStream(
                                       "./src/nl/vandenzen/pdfa1b/resources/sRGB Color Space Profile.icm"));
             writer.setOutputIntents("Custom", "", "http://www.color.org",
                          "sRGB IEC61966-2.1", icc);

             // All fonts should be embedded.
             Font bold10 = FontFactory.getFont(
                          "./src/nl/vandenzen/pdfa1b/resources/arial.ttf",
                          BaseFont.WINANSI, BaseFont.EMBEDDED, 10);

             if (bold10.getFamilyname().equals("unknown")) {
                    throw new FileNotFoundException("Font file not found.");
             }
             final String anchorName = "a";
             HashMap<String, Object> attribs = new HashMap<>();

             // Create a link to another paragraph, with an embedded font as
             // required for pdf/a-1b
             Chunk chunkWithLink = new Chunk("See addendum A", bold10);
             // attribs.put("F", 4 + 8 + 16);
             chunkWithLink.setLocalGoto(anchorName);

             // Adding empty attribs avoids the error message
             // "com.itextpdf.text.DocumentException:
             // com.itextpdf.text.pdf.PdfAConformanceException:
             // An annotation dictionary shall contain the F key."
             chunkWithLink.setAttributes(attribs);

             Paragraph p = new Paragraph();
             p.add(chunkWithLink);
             Chapter chapter = new Chapter(p, 1);
             chapter.setNumberDepth(0);
             document.add(chapter);
             // Create some space between the paragraphs
             for (int i = 0; i < 140; i++) {
                    Chunk space = new Chunk("-----", bold10);
                    Paragraph ps = new Paragraph();
                    ps.add(space);
                    document.add(ps);
             }

             document.newPage();
             // Create an anchor for the addendum
             Chunk chunkAddendum = new Chunk(
                          "This is some extra information about something", bold10);
             chunkAddendum.setLocalDestination(anchorName);

             Paragraph p1 = new Paragraph();
             p1.add(chunkAddendum);
             document.add(p1);

             document.close();
       }
}
Met vriendelijke groet,

Carl van Denzen
Consultant

ma-do 09:00-17:30

[cid:[email protected]]

E [email protected]<mailto:[email protected]> |  M +31 6 4339 2584 | T +31 88 660 3000 | W www.pinkroccade-healthcare.nl<http://www.pinkroccade-healthcare.nl/> | KvK 27322973 Apeldoorn

<http://>[cid:[email protected]]<http://www.twitter.com/pinkroccade>

[cid:[email protected]]<http://www.pinkroccade-healthcare.nl/>banner

Disclaimer | The information transmitted is intended only for use by the addressee and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of it, or the taking of any action in reliance upon this information by persons and/or entities other than the intended recipient is prohibited. If you received this in error, please inform the sender and/or addressee immediately and delete the material. Thank you.
[cid:[email protected]]Please consider the environment before printing this email

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net

_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
image70faca.GIF (image/gif, 7 KB) - not displayed
image9e9db8.GIF (image/gif, 527 B) - not displayed
imagec4b5aa.PNG (image/png, 127.4 KB) - not displayed
image7d702b.GIF (image/gif, 298 B) - not displayed