Skip to content

Commit 69d4c42

Browse files
committed
Compare producer line on document info comparison
Note that pdfXFA and iTextSharp producer line is treated the same way as regular iText one. DEVSIX-1870
1 parent 843cf3d commit 69d4c42

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

kernel/src/main/java/com/itextpdf/kernel/utils/CompareTool.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ public class CompareTool {
131131
private static final String gsParams = " -dNOPAUSE -dBATCH -sDEVICE=png16m -r150 -sOutputFile='<outputfile>' '<inputfile>'";
132132
private static final String compareParams = " '<image1>' '<image2>' '<difference>'";
133133

134+
private static final String versionRegexp = "(iText\u00ae( pdfX(FA|fa))?|iTextSharp\u2122) (\\d\\.)+\\d(-SNAPSHOT)?";
135+
private static final String versionReplacement = "iText\u00ae <version>";
136+
private static final String copyrightRegexp = "\u00a9\\d+-\\d+ iText Group NV";
137+
private static final String copyrightReplacement = "\u00a9<copyright years> iText Group NV";
134138

135139
private String gsExec;
136140
private String compareExec;
@@ -650,7 +654,7 @@ public String compareDocumentInfo(String outPdf, String cmpPdf, byte[] outPass,
650654
String[] outInfo = convertInfo(outDocument.getDocumentInfo());
651655
for (int i = 0; i < cmpInfo.length; ++i) {
652656
if (!cmpInfo[i].equals(outInfo[i])){
653-
message = "Document info fail";
657+
message = MessageFormatUtil.format("Document info fail. Expected: \"{0}\", actual: \"{1}\"", cmpInfo[i], outInfo[i]);
654658
break;
655659
}
656660
}
@@ -1614,7 +1618,7 @@ private int getExplicitDestinationPageNum(PdfArray explicitDest) {
16141618
}
16151619

16161620
private String[] convertInfo(PdfDocumentInfo info) {
1617-
String[] convertedInfo = new String[]{"", "", "", ""};
1621+
String[] convertedInfo = new String[]{"", "", "", "", ""};
16181622
String infoValue = info.getTitle();
16191623
if (infoValue != null)
16201624
convertedInfo[0] = infoValue;
@@ -1627,9 +1631,16 @@ private String[] convertInfo(PdfDocumentInfo info) {
16271631
infoValue = info.getKeywords();
16281632
if (infoValue != null)
16291633
convertedInfo[3] = infoValue;
1634+
infoValue = info.getProducer();
1635+
if (infoValue != null) {
1636+
convertedInfo[4] = convertProducerLine(infoValue);
1637+
}
16301638
return convertedInfo;
16311639
}
16321640

1641+
private String convertProducerLine(String producer) {
1642+
return producer.replaceAll(versionRegexp, versionReplacement).replaceAll(copyrightRegexp, copyrightReplacement);
1643+
}
16331644

16341645
private class PngFileFilter implements FileFilter {
16351646

kernel/src/test/java/com/itextpdf/kernel/utils/CompareToolTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,12 @@ public void compareToolErrorReportTest04() throws InterruptedException, IOExcept
122122
Assert.assertTrue("CompareTool report differs from the reference one", compareTool.compareXmls(sourceFolder + "cmp_report01.xml", destinationFolder + "simple_pdf.report.xml"));
123123

124124
}
125+
126+
@Test
127+
public void differentProducerTest() throws IOException {
128+
String expectedMessage = "Document info fail. Expected: \"iText\u00ae <version> \u00a9<copyright years> iText Group NV (iText Software; licensed version)\", actual: \"iText\u00ae <version> \u00a9<copyright years> iText Group NV (AGPL-version)\"";
129+
String licensed = sourceFolder + "producerLicensed.pdf";
130+
String agpl = sourceFolder + "producerAGPL.pdf";
131+
Assert.assertEquals(expectedMessage, new CompareTool().compareDocumentInfo(agpl, licensed));
132+
}
125133
}
Binary file not shown.

0 commit comments

Comments
 (0)