Skip to content

Commit 3f9968c

Browse files
committed
Add itext fingerprints; update handling of producer info;
1 parent a5b8c12 commit 3f9968c

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfDocument.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,9 +1298,29 @@ protected void open(PdfVersion newPdfVersion) {
12981298
catalog = new PdfCatalog(this);
12991299
info = new PdfDocumentInfo(this).addCreationDate();
13001300
info.addModDate();
1301-
info.setProducer(Version.getInstance().getVersion());
1301+
info.getPdfObject().put(PdfName.Producer, new PdfString(Version.getInstance().getVersion()));
13021302
} else {
13031303
info.addModDate();
1304+
String producer = null;
1305+
if (info.getPdfObject().containsKey(PdfName.Producer)) {
1306+
producer = info.getPdfObject().getAsString(PdfName.Producer).toUnicodeString();
1307+
}
1308+
Version version = Version.getInstance();
1309+
if (producer == null || !version.getVersion().contains(version.getProduct())) {
1310+
producer = version.getVersion();
1311+
} else {
1312+
int idx = producer.indexOf("; modified using");
1313+
StringBuilder buf;
1314+
if (idx == -1) {
1315+
buf = new StringBuilder(producer);
1316+
} else {
1317+
buf = new StringBuilder(producer.substring(0, idx));
1318+
}
1319+
buf.append("; modified using ");
1320+
buf.append(version.getVersion());
1321+
producer = buf.toString();
1322+
}
1323+
info.getPdfObject().put(PdfName.Producer, new PdfString(producer));
13041324
}
13051325
trailer = new PdfDictionary();
13061326
trailer.put(PdfName.Root, catalog.getPdfObject().getIndirectReference());

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfDocumentInfo.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ public PdfDocumentInfo setCreator(String creator) {
9393
return this;
9494
}
9595

96-
public PdfDocumentInfo setProducer(String creator) {
97-
getPdfObject().put(PdfName.Producer, new PdfString(creator));
98-
return this;
99-
}
100-
10196
public String getTitle() {
10297
return getStringValue(PdfName.Title);
10398
}

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfXrefTable.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ This file is part of the iText (R) project.
4646

4747
import com.itextpdf.io.source.ByteUtils;
4848
import com.itextpdf.kernel.PdfException;
49+
import com.itextpdf.kernel.Version;
4950

5051
import java.io.IOException;
5152
import java.io.Serializable;
@@ -304,9 +305,10 @@ protected void writeXrefTableAndTrailer(PdfDocument document, PdfObject fileId,
304305
trailer.put(PdfName.Prev, lastXref);
305306
}
306307
writer.write(document.getTrailer());
308+
writer.write('\n');
307309
}
308-
309-
writer.writeString("\nstartxref\n").
310+
writeKeyInfo(writer);
311+
writer.writeString("startxref\n").
310312
writeLong(startxref).
311313
writeString("\n%%EOF\n");
312314
xref = null;
@@ -322,6 +324,14 @@ void clear() {
322324
count = 1;
323325
}
324326

327+
protected static void writeKeyInfo(PdfWriter writer) throws IOException {
328+
Version version = Version.getInstance();
329+
String k = version.getKey();
330+
if (k == null) {
331+
k = "iText";
332+
}
333+
writer.writeString(String.format("%%%s-%s\n", k, version.getRelease()));
334+
}
325335

326336
private void ensureCount(int count) {
327337
if (count >= xref.length) {

0 commit comments

Comments
 (0)