private void compareDocumentsEncryption(PdfDocument outDocument, PdfDocument cmpDocument, CompareResult compareResult) { PdfDictionary outEncrypt = outDocument.getTrailer().getAsDictionary(PdfName.Encrypt); PdfDictionary cmpEncrypt = cmpDocument.getTrailer().getAsDictionary(PdfName.Encrypt);
private PageRange getNextRange(int startPage, int endPage, long size) { PdfResourceCounter counter = new PdfResourceCounter(pdfDocument.getTrailer()); Map<Integer, PdfObject> resources = counter.getResources(); long lengthWithoutXref = counter.getLength(null); // initialize with trailer length int currentPage = startPage; boolean oversized = false; do { PdfPage page = pdfDocument.getPage(currentPage++); counter = new PdfResourceCounter(page.getPdfObject()); lengthWithoutXref += counter.getLength(resources); resources.putAll(counter.getResources()); if (lengthWithoutXref + xrefLength(resources.size()) > size) { oversized = true; } } while (currentPage <= endPage && !oversized); // true if at least the first page to be copied didn't cause the oversize if (oversized && (currentPage - 1) != startPage) { // we shouldn't copy previous page because it caused // the oversize and it isn't the first page to be copied --currentPage; } return new PageRange().addPageSequence(startPage, currentPage - 1); }
/** * Adds keys to the signature dictionary that define the certification level and the permissions. * This method is only used for Certifying signatures. * * @param crypto the signature dictionary */ protected void addDocMDP(PdfSignature crypto) { PdfDictionary reference = new PdfDictionary(); PdfDictionary transformParams = new PdfDictionary(); transformParams.put(PdfName.P, new PdfNumber(certificationLevel)); transformParams.put(PdfName.V, new PdfName("1.2")); transformParams.put(PdfName.Type, PdfName.TransformParams); reference.put(PdfName.TransformMethod, PdfName.DocMDP); reference.put(PdfName.Type, PdfName.SigRef); reference.put(PdfName.TransformParams, transformParams); setDigestParamToSigRefIfNeeded(reference); reference.put(PdfName.Data, document.getTrailer().get(PdfName.Root)); PdfArray types = new PdfArray(); types.add(reference); crypto.put(PdfName.Reference, types); }
/** * Adds keys to the signature dictionary that define the certification level and the permissions. * This method is only used for Certifying signatures. * * @param crypto the signature dictionary */ protected void addDocMDP(PdfSignature crypto) { PdfDictionary reference = new PdfDictionary(); PdfDictionary transformParams = new PdfDictionary(); transformParams.put(PdfName.P, new PdfNumber(certificationLevel)); transformParams.put(PdfName.V, new PdfName("1.2")); transformParams.put(PdfName.Type, PdfName.TransformParams); reference.put(PdfName.TransformMethod, PdfName.DocMDP); reference.put(PdfName.Type, PdfName.SigRef); reference.put(PdfName.TransformParams, transformParams); setDigestParamToSigRefIfNeeded(reference); reference.put(PdfName.Data, document.getTrailer().get(PdfName.Root)); PdfArray types = new PdfArray(); types.add(reference); crypto.put(PdfName.Reference, types); }
/** * This method checks a number of document-wide requirements of the PDF/A * standard. The algorithms of some of these checks vary with the PDF/A * level and thus are implemented in subclasses; others are implemented * as private methods in this class. * * @param catalog The catalog being checked */ public void checkDocument(PdfCatalog catalog) { PdfDictionary catalogDict = catalog.getPdfObject(); setPdfAOutputIntentColorSpace(catalogDict); checkOutputIntents(catalogDict); checkMetaData(catalogDict); checkCatalogValidEntries(catalogDict); checkTrailer(catalog.getDocument().getTrailer()); checkLogicalStructure(catalogDict); checkForm(catalogDict.getAsDictionary(PdfName.AcroForm)); checkOutlines(catalogDict); checkPages(catalog.getDocument()); checkOpenAction(catalogDict.get(PdfName.OpenAction)); checkColorsUsages(); }
/** * This method checks a number of document-wide requirements of the PDF/A * standard. The algorithms of some of these checks vary with the PDF/A * level and thus are implemented in subclasses; others are implemented * as private methods in this class. * * @param catalog The catalog being checked */ public void checkDocument(PdfCatalog catalog) { PdfDictionary catalogDict = catalog.getPdfObject(); setPdfAOutputIntentColorSpace(catalogDict); checkOutputIntents(catalogDict); checkMetaData(catalogDict); checkCatalogValidEntries(catalogDict); checkTrailer(catalog.getDocument().getTrailer()); checkLogicalStructure(catalogDict); checkForm(catalogDict.getAsDictionary(PdfName.AcroForm)); checkOutlines(catalogDict); checkPages(catalog.getDocument()); checkOpenAction(catalogDict.get(PdfName.OpenAction)); checkColorsUsages(); }
PdfDictionary trailer = document.getTrailer(); trailer.put(PdfName.Prev, lastXref); writer.write(document.getTrailer()); writer.write('\n');
/** * Adds keys to the signature dictionary that define the field permissions. * This method is only used for signatures that lock fields. * * @param crypto the signature dictionary */ protected void addFieldMDP(PdfSignature crypto, PdfSigFieldLock fieldLock) { PdfDictionary reference = new PdfDictionary(); PdfDictionary transformParams = new PdfDictionary(); transformParams.putAll(fieldLock.getPdfObject()); transformParams.put(PdfName.Type, PdfName.TransformParams); transformParams.put(PdfName.V, new PdfName("1.2")); reference.put(PdfName.TransformMethod, PdfName.FieldMDP); reference.put(PdfName.Type, PdfName.SigRef); reference.put(PdfName.TransformParams, transformParams); setDigestParamToSigRefIfNeeded(reference); reference.put(PdfName.Data, document.getTrailer().get(PdfName.Root)); PdfArray types = crypto.getPdfObject().getAsArray(PdfName.Reference); if (types == null) { types = new PdfArray(); crypto.put(PdfName.Reference, types); } types.add(reference); }
/** * Adds keys to the signature dictionary that define the field permissions. * This method is only used for signatures that lock fields. * * @param crypto the signature dictionary */ protected void addFieldMDP(PdfSignature crypto, PdfSigFieldLock fieldLock) { PdfDictionary reference = new PdfDictionary(); PdfDictionary transformParams = new PdfDictionary(); transformParams.putAll(fieldLock.getPdfObject()); transformParams.put(PdfName.Type, PdfName.TransformParams); transformParams.put(PdfName.V, new PdfName("1.2")); reference.put(PdfName.TransformMethod, PdfName.FieldMDP); reference.put(PdfName.Type, PdfName.SigRef); reference.put(PdfName.TransformParams, transformParams); setDigestParamToSigRefIfNeeded(reference); reference.put(PdfName.Data, document.getTrailer().get(PdfName.Root)); PdfArray types = crypto.getPdfObject().getAsArray(PdfName.Reference); if (types == null) { types = new PdfArray(); crypto.put(PdfName.Reference, types); } types.add(reference); }
nodes = loader.getNodes(); PdfTrailerTreeNode root = pdfTree.getRoot(); root.setTrailer(loader.getFile().getPdfDocument().getTrailer()); root.setUserObject("PDF Object Tree (" + loader.getLoaderName() + ")"); nodes.expandNode(root);