Package com.itextpdf.pdfoptimizer.util
Class DocumentStructureUtils
java.lang.Object
com.itextpdf.pdfoptimizer.util.DocumentStructureUtils
Util class for typical tasks across the whole structure of
PdfDocument.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Mapcom.itextpdf.kernel.pdf.PdfObject> getSimilarDictionaries(com.itextpdf.kernel.pdf.PdfDocument document, Collection objects, PdfDictionaryEqualityCalculator eqCalculator) Goes over provided list of objects and checks for similar ones.getSimilarDictionariesList(Collection objects, PdfDictionaryEqualityCalculator eqCalculator) Gets the list of groups of the similar objects.static Listsearch(com.itextpdf.kernel.pdf.PdfDocument document, IPdfObjectPredicate predicate) Collects all objects matches the provided predicate.static voidGoes across all the structure of the document starting from indirect objects definition and then through its children recursively.
-
Method Details
-
search
public static Listsearch (com.itextpdf.kernel.pdf.PdfDocument document, IPdfObjectPredicate predicate) Collects all objects matches the provided predicate.- Parameters:
-
document- is aPdfDocumentto perform a search -
predicate- is aIPdfObjectPredicate - Returns:
- list of all indirect objects match the predicate
-
traverse
Goes across all the structure of the document starting from indirect objects definition and then through its children recursively. Every met indirect object definition is processed byIAction.processIndirectObjectDefinition(PdfObject)and every met object including both types direct and indirect are is processed withIAction.processObject(PdfObject)call. Allows to replace objects during traversing (seeIAction.processObject(PdfObject)for details).- Parameters:
-
document- is aPdfDocumentto perform a traversing -
action- is an action to perform during traversing
-
getSimilarDictionaries
public static Mapcom.itextpdf.kernel.pdf.PdfObject> getSimilarDictionaries(com.itextpdf.kernel.pdf.PdfDocument document, Collection objects, PdfDictionaryEqualityCalculator eqCalculator) Goes over provided list of objects and checks for similar ones. If there are similar objects, creates an indirect reference in provided document for the first encountered object and puts all copies to the resulting map as keys, and the first encountered one as value. The resulting map can be further used inReplaceObjectsActionto replace all duplicates with a single indirect reference.- Parameters:
-
document- document containing provided list of pdf objects -
objects- collection ofPdfDictionaryelements -
eqCalculator- compare tool forPdfDictionaryobjects - Returns:
-
Map of
PdfDictionaryobjects, where keys are found duplicates and values are first encountered object.
-
getSimilarDictionariesList
public static List<List> getSimilarDictionariesList(Collection objects, PdfDictionaryEqualityCalculator eqCalculator) Gets the list of groups of the similar objects.- Parameters:
-
objects- the objects to look for similarities -
eqCalculator- compare tool for objects - Returns:
-
the list of groups of the objects similar to each other according to
eqCalculator
-