Op 16/02/2012 18:57, AJ Weber schreef:
> Would I:
> 1) Open existing PDF in PdfReader;
Yes.
> 2) Use similar classes to OCGParser/Remover to operate on the reader;
Yes.
> 3) Create a PdfCopy or PdfStamper to then simply copy the reader to a
> new output PDF (and I assume the changes made to the reader-interface
> would be applied to the output)?
PdfStamper, NOT PdfCopy.
For instance:
public static void main(String[] args) throws IOException,
DocumentException {
PdfReader reader = new PdfReader("original.pdf");
MyParser parser = new MyParser(args[0]);
PdfDictionary page;
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
page = reader.getPageN(i);
PRStream stream = (PRStream)page.getAsStream(PdfName.CONTENTS);
PdfDictionary resources = page.getAsDict(PdfName.RESOURCES);
parser.parse(stream, resources);
}
reader.removeUnusedObjects();
PdfStamper stamper = new PdfStamper(reader, new
FileOutputStream("fixed.pdf"));
stamper.close();
}
MyParser parses and copies all PDF syntax, except for some particular
part defined by args[0].
Note that this code snippet assumes that the /Contents element in the
page dictionary is a stream. In your case it could be an array in which
case the code will throw a ClassCastException.
I suggest that you start by removing everything from the OCG parser
keeping the dummy operator.
This should result in code that makes a copy of the original file.
Then you'd need to find out which operator is used to add the part you
want to remove.
Create a custom operator class that does exactly the same thing as the
dummy operator, except when the part you don't want to copy is encountered.
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
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