Op 5/01/2011 18:23, Paul Cooper schreef:
Wow.

How so, wow?

So, shouldn’t this code be removed from your library, as it seems to be
useless and bug-inducing?

See the attached example. Are you saying the code is useless? If I have a file ocg.pdf, then I can use the code to get info about PdfLayers and I can apply changes. The file ocg.pdf is changed into ocg_altered.pdf without throwing an exception.

As for paying for a custom solution…we’ll just generate two different
files and switch the filenames….

That's fine by me if that works for you, but there's no reason for you to say that iText is useless.
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfLayer;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;


public class ExistingOCG {

        public static void main(String[] args) throws IOException, 
DocumentException {
                PdfReader reader = new PdfReader("ocg.pdf");
                PdfStamper stamper =
                        new PdfStamper(reader, new 
FileOutputStream("ocg_altered.pdf"));
                Map<String, PdfLayer> layers = stamper.getPdfLayers();
                PdfLayer layer;
                for (Map.Entry<String, PdfLayer> entry : layers.entrySet()) {
                        System.out.println(entry.getKey());
                        layer = entry.getValue();
                        System.out.println(layer.isOn());
                }
                PdfLayer layer1 = (PdfLayer)layers.get("Group: layer 1");
                layer1.setOn(false);
                PdfLayer layer2 = (PdfLayer)layers.get("Group: layer 2");
                layer2.setOn(false);
                stamper.close();
        }
}

Attachment: ocg.pdf
Description: Adobe PDF document

Attachment: ocg_altered.pdf
Description: Adobe PDF document

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

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

Reply via email to