public void optimize() { LOG.trace("Optimizing document"); ResourcesHitter hitter = new ResourcesHitter(); pagesLookup.values().forEach(p -> { // each page must have it's own resource dic and it's own xobject and font name dic // so we don't optimize shared resource dic or xobjects/fonts name dictionaries COSDictionary resources = ofNullable(p.getResources().getCOSObject()).map(COSDictionary::duplicate) .orElseGet(COSDictionary::new); // resources are cached in the PDPage so make sure they are replaced p.setResources(new PDResources(resources)); ofNullable(resources.getDictionaryObject(COSName.XOBJECT, COSDictionary.class)).filter(Objects::nonNull) .map(COSDictionary::duplicate).ifPresent(d -> resources.setItem(COSName.XOBJECT, d)); ofNullable(resources.getDictionaryObject(COSName.FONT, COSDictionary.class)).filter(Objects::nonNull) .map(COSDictionary::duplicate).ifPresent(d -> resources.setItem(COSName.FONT, d)); hitter.accept(p); }); new ResourceDictionaryCleaner().accept(destinationDocument.getUnderlyingPDDocument()); }
public void optimize() { LOG.trace("Optimizing document"); ResourcesHitter hitter = new ResourcesHitter(); pagesLookup.values().forEach(p -> { // each page must have it's own resource dic and it's own xobject and font name dic // so we don't optimize shared resource dic or xobjects/fonts name dictionaries COSDictionary resources = ofNullable(p.getResources().getCOSObject()).map(COSDictionary::duplicate) .orElseGet(COSDictionary::new); // resources are cached in the PDPage so make sure they are replaced p.setResources(new PDResources(resources)); ofNullable(resources.getDictionaryObject(COSName.XOBJECT, COSDictionary.class)).filter(Objects::nonNull) .map(COSDictionary::duplicate).ifPresent(d -> resources.setItem(COSName.XOBJECT, d)); ofNullable(resources.getDictionaryObject(COSName.FONT, COSDictionary.class)).filter(Objects::nonNull) .map(COSDictionary::duplicate).ifPresent(d -> resources.setItem(COSName.FONT, d)); hitter.accept(p); }); new ResourceDictionaryCleaner().accept(destinationDocument.getUnderlyingPDDocument()); }
/** * Removes unnecessary annotations and updates the relevant ones with the new generated pages so that link annotations, etc are poiting to valid pages */ public void saintizeAnnotations() { clipSignatures(new AnnotationsDistiller(handler.getUnderlyingPDDocument()).retainRelevantAnnotations(lookups) .values()); }
public void save(File file, boolean discardOutline) throws TaskException { if (!discardOutline) { createOutline(); } LookupTable<PDAnnotation> annotations = new AnnotationsDistiller(origin).retainRelevantAnnotations(pagesLookup); clipSignatures(annotations.values()); acroFormsMerger.mergeForm(origin.getDocumentCatalog().getAcroForm(), annotations); ofNullable(acroFormsMerger.getForm()).filter(f -> !f.getFields().isEmpty()).ifPresent(f -> { LOG.debug("Adding generated AcroForm"); destinationDocument.setDocumentAcroForm(f); }); destinationDocument.savePDDocument(file); }
/** * Removes unnecessary annotations and updates the relevant ones with the new generated pages so that link annotations, etc are poiting to valid pages */ public void saintizeAnnotations() { clipSignatures(new AnnotationsDistiller(handler.getUnderlyingPDDocument()).retainRelevantAnnotations(lookups) .values()); }
public void save(File file, boolean discardOutline) throws TaskException { if (!discardOutline) { createOutline(); } LookupTable<PDAnnotation> annotations = new AnnotationsDistiller(origin).retainRelevantAnnotations(pagesLookup); clipSignatures(annotations.values()); acroFormsMerger.mergeForm(origin.getDocumentCatalog().getAcroForm(), annotations); ofNullable(acroFormsMerger.getForm()).filter(f -> !f.getFields().isEmpty()).ifPresent(f -> { LOG.debug("Adding generated AcroForm"); destinationDocument.setDocumentAcroForm(f); }); destinationDocument.savePDDocument(file); }
.collect(Collectors.toList())); annotationsLookup.values().stream().filter(a -> a instanceof PDAnnotationWidget) .filter(a -> a.getCOSObject().containsKey(COSName.T)).map(a -> (PDAnnotationWidget) a).collect(toList()) .forEach(w -> {
.collect(Collectors.toList())); annotationsLookup.values().stream().filter(a -> a instanceof PDAnnotationWidget) .filter(a -> a.getCOSObject().containsKey(COSName.T)).map(a -> (PDAnnotationWidget) a).collect(toList()) .forEach(w -> {
@Test public void values() { victim.addLookupEntry("this", "that"); victim.addLookupEntry("this1", "that1"); victim.addLookupEntry("this2", "that2"); assertEquals(3, victim.values().size()); }
@Test public void keys() { victim.addLookupEntry("this", "that"); victim.addLookupEntry("this1", "that1"); victim.addLookupEntry("this", "that2"); assertEquals(2, victim.values().size()); } }
clipSignatures(annotationsLookup.values());
clipSignatures(annotationsLookup.values());
clipSignatures(annotationsLookup.values());
clipSignatures(annotationsLookup.values());
clipSignatures(annotationsLookup.values());
clipSignatures(annotationsLookup.values());