Discussion:
[iText-questions] PDF/A and LocalGoto not working
Denzen, van Carl
2014-12-22 15:25:45 UTC
Permalink
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:***@9e3b06fa.4fa3c6ca]

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

<Loading Image...@1553752d.45836c24]<http://www.twitter.com/pinkroccade>

[cid:***@ccc9d6c3.418c7d4b]<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:***@7866dfca.4a85bced]Please consider the environment before printing this email
iText mailing list
2014-12-23 07:14:48 UTC
Permalink
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've tested your code sample and I can reproduce the problem if we
remove the following line:

chunkWithLink.setAttributes(attribs);

It seems that this line provides a workaround, but that's not an elegant
solution. I've created a ticket in our issue tracker, and we'll have
this problem fixed in the next release.
Denzen, van Carl
2014-12-23 10:56:29 UTC
Permalink
My first mailing was not accurate enough. The problem you have caught in removing the “setAttributes” line will lead to an error while running the code. This is another problem (that also occurs in a more severe way in iTextSharp, I cannot find a workaround for it in iTextSharp).
The problem I intended to submit was the fact that I can make a pdf, but in the created pdf file, the link doesn’t work: the pointer in the reader doesn’t change to a hand if I hover over the text that was meant as the localGoto.


Met vriendelijke groet,

Carl van Denzen
Consultant

ma-do 09:00-17:30

[cid:***@aeabf0db.48b3b072]

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

<Loading Image...@ecd46efd.48b7ff0f]<http://www.twitter.com/pinkroccade>

[cid:***@11a05e53.47b88ea5]<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:***@d80559c5.4aaa3e01]Please consider the environment before printing this email
Van: iText mailing list [mailto:***@1t3xt.info]
Verzonden: dinsdag 23 december 2014 8:15
Aan: itext-***@lists.sourceforge.net
Onderwerp: Re: [iText-questions] PDF/A and LocalGoto not working

On 12/22/2014 16:25 PM, Denzen, van Carl wrote:
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've tested your code sample and I can reproduce the problem if we remove the following line:

chunkWithLink.setAttributes(attribs);

It seems that this line provides a workaround, but that's not an elegant solution. I've created a ticket in our issue tracker, and we'll have this problem fixed in the next release.
Raf Hens
2014-12-23 13:10:22 UTC
Permalink
Post by Denzen, van Carl
My first mailing was not accurate enough. The problem you have caught in
removing the “setAttributes” line will lead to an error while running
the code. This is another problem (that also occurs in a more severe way
in iTextSharp, I cannot find a workaround for it in iTextSharp).
The problem I intended to submit was the fact that I can make a pdf, but
in the created pdf file, the link doesn’t work: the pointer in the
reader doesn’t change to a hand if I hover over the text that was meant
as the localGoto.
The exception about the missing F key is already fixed in the 5.5.4
release. You probably upgraded your itext jar, but not your itext-pdfa jar.

The reason you don't get a working link when you add the "setAttributes"
call, is that a GoTo is stored as an attribute of a Chunk. This is
later converted into a link annotation. By overriding the attributes
with a blank map, you are effectively undoing your "setLocalGoto" call.

I'll check if there's a porting issue in iTextSharp wrt to F key error.

Your code sample did expose a different problem. This is related to
outputintents and icc profiles. The fix is in rev 6658.

Best regards,
Raf

------------------------------------------------------------------------------
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
iText-***@lists.sourceforge.net
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
Raf Hens
2014-12-23 13:48:25 UTC
Permalink
Post by Denzen, van Carl
My first mailing was not accurate enough. The problem you have caught in
removing the “setAttributes” line will lead to an error while running
the code. This is another problem (that also occurs in a more severe way
in iTextSharp, I cannot find a workaround for it in iTextSharp).
The problem I intended to submit was the fact that I can make a pdf, but
in the created pdf file, the link doesn’t work: the pointer in the
reader doesn’t change to a hand if I hover over the text that was meant
as the localGoto.
The exception about the missing F key is already fixed in the 5.5.4
release. You probably upgraded your itext jar, but not your itext-pdfa jar.

The reason you don't get a working link when you add the "setAttributes"
call, is that a GoTo is stored as an attribute of a Chunk. This is
later converted into a link annotation. By overriding the attributes
with a blank map, you are effectively undoing your "setLocalGoto" call.

I'll check if there's a porting issue in iTextSharp wrt to F key error.

Your code sample did expose a different problem. This is related to
outputintents and icc profiles. The fix is in rev 6658.

Best regards,
Raf
--
Raf Hens
Director of Engineering
iText Software

------------------------------------------------------------------------------
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
iText-***@lists.sourceforge.net
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
Loading...