Hello,
We are evaluating iText 5.5.1 for our needs and I came upon the following
peculiarity. We want to generate a PDF that has layers (optional content
groups or OCGs) where one layer is only shown when viewed in a reader and not
when printed and the other layer is only shown when printed but not in online
view.
I worked from one of the iText examples and created the PDF with this code
(just part to keep length of post short):
...
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream(file));
writer.setPdfVersion(PdfWriter.VERSION_1_5);
document.open();
PdfContentByte cb = writer.getDirectContent();
// 1) generate only View:
PdfLayer not_printed = new PdfLayer("not printed", writer);
not_printed.setOnPanel(ON_PANEL);
not_printed.setOn(true);
not_printed.setPrint("Print", false);
cb.beginLayer(not_printed);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase(
"ONLY IN VIEW"), 50, 600, 0);
cb.endLayer();
// 2) generate only Print:
PdfLayer only_printed = new PdfLayer("only printed", writer);
only_printed.setOnPanel(ON_PANEL);
only_printed.setView(false);
only_printed.setPrint("Print", true); // <- this turns out to be the
culprit...
cb.beginLayer(only_printed);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase(
"ONLY WHEN PRINTED"), 50, 400, 0);
cb.endLayer();
document.close();
...
This generates a PDF that has the two phrases "ONLY IN VIEW" and "ONLY WHEN
PRINTED" at different locations on the first page. Opening the resulting PDF
in Chrome browser, the first phrase shows and when clicking Print, the preview
shows only the second phrase. This is what I had intended.
Now opening the same PDF in Adobe Reader 11, the view is correct (only the
first phrase shows) but when I click Print, the preview shows neither the
second (his would be correct) nor the first (this would be incorrect) phrase --
the page is just blank. Poking around with the excellent RUPS tool (thank
you!) and editing the PDF with Acrobat Pro, I realized that after Acrobat Pro,
the /PrintState setting is /ON but iText originally generated the value /on --
it seems that Adobe Reader is case sensitive here! I used RUPS to edit the
iText generated PDF as well and simply replaced /on with /ON for the
/PrintState and -- voila -- Adobe Reader behaves as I would expect showing the
second phrase in the print preview.
A quick look into the class com.itextpdf.text.pdf.PdfName.ON reveals that the
string is indeed lower case. However, the corresponding PdfName.OFF is upper
case (and there is a PdfName.Off that is mixed case). I think our problem
could be fixed by patching PdfName.ON to be instantiated with "ON" rather than
"on" -- would this be of interest by iText? I'd b happy to provide more
details, code, and even my little unit test that I wrote against it.
>From browsing quickly through the code bases, I only see PdfName.ON used in
>the context of OCGs, where the upper case might be the right way to go.
Thanks,
Linda
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
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