Hi,

This is not a general problem and only occurs with original PDF generated with 
3D content using Anark. The file when loaded seems to have encrypted and loads 
just find in Adobe Reader, but when we try to do a "Save As" we get the 
following error:
"The document could not be saved. There was a problem reading this document 21."

If I do a control click on the "ok" button. I get the following message:
"This direct object already has a container."

Any ideas what might be causing this problem? We have tried the same thing with 
iText and it does not experience this problem.

Sample Code that reproduces the problem:
                                PDDocument doc = null;

                                try {
                                                doc = PDDocument.load(pdfIn);
                                                PDPage page = null;
                                                AccessPermission apermission = 
new AccessPermission();
                                                
apermission.setCanAssembleDocument(false);
                                                
apermission.setCanExtractContent(false);
                                                
apermission.setCanExtractForAccessibility(true);
                                                
apermission.setCanFillInForm(true);
                                                
apermission.setCanModifyAnnotations(true);
                                                apermission.setCanPrint(true);
                                                apermission.setReadOnly();
                                                StandardProtectionPolicy spp = 
new StandardProtectionPolicy(UUID.randomUUID().toString(), "", apermission);
                                                doc.protect(spp);

                                                for (int i = 0; i < 
doc.getNumberOfPages(); i++) {
                                                                page = 
doc.getPage(i);
                                                                
PDPageContentStream canvas = new PDPageContentStream(doc, page, 
PDPageContentStream.AppendMode.APPEND, true, true);
                                                                
canvas.saveGraphicsState();
                                                                
canvas.restoreGraphicsState();
                                                                canvas.close();
                                                }
                                                doc.save(pdfOut);
                                                bRet = true;
                                }
                                finally {
                                                if (doc != null) {
                                                                doc.close();
                                                }
                                }

Thanks,
Patrick

Reply via email to