@@ -97,8 +97,6 @@ public class DocumentRevisionsValidator {
97
97
static final String FIELD_NOT_DICTIONARY =
98
98
"Form field \" {0}\" or one of its widgets is not a dictionary. It will not be validated." ;
99
99
static final String FIELD_REMOVED = "Form field {0} was removed or unexpectedly modified." ;
100
- static final String LINEARIZED_NOT_SUPPORTED =
101
- "Linearized PDF documents are not supported by DocumentRevisionsValidator." ;
102
100
static final String LOCKED_FIELD_KIDS_ADDED =
103
101
"Kids were added to locked form field \" {0}\" ." ;
104
102
static final String LOCKED_FIELD_KIDS_REMOVED =
@@ -251,6 +249,7 @@ ValidationReport validateAllDocumentRevisions(ValidationContext context, PdfDocu
251
249
ReportItemStatus .INDETERMINATE ));
252
250
return report ;
253
251
}
252
+ mergeRevisionsInLinearizedDocument (document , documentRevisions );
254
253
SignatureUtil signatureUtil = new SignatureUtil (document );
255
254
List <String > signatures = new ArrayList <>(signatureUtil .getSignatureNames ());
256
255
if (signatures .isEmpty ()) {
@@ -326,6 +325,28 @@ void validateRevision(DocumentRevision previousRevision, DocumentRevision curren
326
325
documentWithoutRevision , documentWithRevision , currentRevision )));
327
326
}
328
327
328
+ private void mergeRevisionsInLinearizedDocument (PdfDocument document , List <DocumentRevision > documentRevisions ) {
329
+ if (documentRevisions .size () > 1 ) {
330
+ // We need to check if document is linearized in first revision
331
+ // We don't need to populate validation report in case of exceptions, it will happen later
332
+ createDocumentAndPerformOperation (documentRevisions .get (0 ), document , new ValidationReport (),
333
+ firstRevisionDocument -> {
334
+ if (isLinearizedPdf (document )) {
335
+ Set <PdfIndirectReference > mergedModifiedReferences =
336
+ new HashSet <>(documentRevisions .get (0 ).getModifiedObjects ());
337
+ mergedModifiedReferences .addAll (documentRevisions .get (1 ).getModifiedObjects ());
338
+ DocumentRevision mergedRevision = new DocumentRevision (
339
+ documentRevisions .get (0 ).getEofOffset (),
340
+ mergedModifiedReferences );
341
+ documentRevisions .add (0 , mergedRevision );
342
+ documentRevisions .remove (1 );
343
+ documentRevisions .remove (1 );
344
+ }
345
+ return true ;
346
+ });
347
+ }
348
+ }
349
+
329
350
private boolean validateRevision (ValidationReport validationReport , ValidationContext context ,
330
351
PdfDocument documentWithoutRevision , PdfDocument documentWithRevision , DocumentRevision currentRevision ) {
331
352
usuallyModifiedObjects = new Pair <>(createUsuallyModifiedObjectsSet (documentWithoutRevision ),
@@ -559,13 +580,8 @@ private boolean createDocumentAndPerformOperation(DocumentRevision revision, Pdf
559
580
new DocumentProperties ().setEventCountingMetaInfo (metaInfo ))) {
560
581
return (boolean ) operation .apply (documentWithRevision );
561
582
} catch (IOException | RuntimeException exception ) {
562
- if (isLinearizedPdf (originalDocument )) {
563
- report .addReportItem (new ReportItem (DOC_MDP_CHECK , LINEARIZED_NOT_SUPPORTED , exception ,
564
- ReportItemStatus .INDETERMINATE ));
565
- } else {
566
- report .addReportItem (new ReportItem (DOC_MDP_CHECK , REVISIONS_READING_EXCEPTION , exception ,
567
- ReportItemStatus .INDETERMINATE ));
568
- }
583
+ report .addReportItem (new ReportItem (DOC_MDP_CHECK , REVISIONS_READING_EXCEPTION , exception ,
584
+ ReportItemStatus .INDETERMINATE ));
569
585
return false ;
570
586
}
571
587
}
0 commit comments