Skip to content

Commit 8f83f02

Browse files
committed
Made PdfDocument.getSerializedBytes() log errors via SLF4J.
Changed CompareTool.compareByCatalog() exception logic.
1 parent 2da9bb1 commit 8f83f02

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

io/src/main/java/com/itextpdf/io/LogMessageConstant.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public class LogMessageConstant {
5454
*/
5555
public static final String DOCUMENT_ALREADY_HAS_FIELD = "The document already has field {0}. Annotations of the fields with this name will be added to the existing one as children. If you want to have separate fields, please, rename them manually before copying.";
5656

57+
/**
58+
* Log message.
59+
*/
60+
public static final String DOCUMENT_SERIALIZATION_EXCEPTION_RAISED = "Unhandled exception while serialization";
61+
5762
/**
5863
* Log message.
5964
*/

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ This file is part of the iText (R) project.
7676
import org.slf4j.Logger;
7777
import org.slf4j.LoggerFactory;
7878

79+
import org.slf4j.Logger;
80+
import org.slf4j.LoggerFactory;
81+
7982
public class PdfDocument implements IEventDispatcher, Closeable, Serializable {
8083

8184
private static final long serialVersionUID = -7041578979319799646L;
@@ -1570,21 +1573,20 @@ private byte[] getSerializedBytes() {
15701573
oos.flush();
15711574
return bos.toByteArray();
15721575
} catch (Exception e) {
1573-
e.printStackTrace();
1576+
Logger logger = LoggerFactory.getLogger(PdfDocument.class);
1577+
logger.warn(LogMessageConstant.DOCUMENT_SERIALIZATION_EXCEPTION_RAISED, e);
15741578
return null;
15751579
} finally {
15761580
if (oos != null) {
15771581
try {
15781582
oos.close();
1579-
} catch (IOException e) {
1580-
e.printStackTrace();
1583+
} catch (IOException ignored) {
15811584
}
15821585
}
15831586
if (bos != null) {
15841587
try {
15851588
bos.close();
1586-
} catch (IOException e) {
1587-
e.printStackTrace();
1589+
} catch (IOException ignored) {
15881590
}
15891591
}
15901592
}

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,14 @@ public CompareTool() {
107107
compareExec = System.getProperty("compareExec");
108108
}
109109

110-
public CompareResult compareByCatalog(PdfDocument outDocument, PdfDocument cmpDocument) {
110+
public CompareResult compareByCatalog(PdfDocument outDocument, PdfDocument cmpDocument) throws IOException {
111111
CompareResult compareResult = null;
112-
try {
113-
compareResult = new CompareResult(compareByContentErrorsLimit);
114-
ObjectPath catalogPath = new ObjectPath(cmpDocument.getCatalog().getPdfObject().getIndirectReference(),
115-
outDocument.getCatalog().getPdfObject().getIndirectReference());
116-
Set<PdfName> ignoredCatalogEntries = new LinkedHashSet<>(Arrays.asList(PdfName.Metadata, PdfName.AcroForm));
117-
compareDictionariesExtended(outDocument.getCatalog().getPdfObject(), cmpDocument.getCatalog().getPdfObject(),
118-
catalogPath, compareResult, ignoredCatalogEntries);
119-
} catch (IOException e) {
120-
e.printStackTrace();
121-
}
112+
compareResult = new CompareResult(compareByContentErrorsLimit);
113+
ObjectPath catalogPath = new ObjectPath(cmpDocument.getCatalog().getPdfObject().getIndirectReference(),
114+
outDocument.getCatalog().getPdfObject().getIndirectReference());
115+
Set<PdfName> ignoredCatalogEntries = new LinkedHashSet<>(Arrays.asList(PdfName.Metadata, PdfName.AcroForm));
116+
compareDictionariesExtended(outDocument.getCatalog().getPdfObject(), cmpDocument.getCatalog().getPdfObject(),
117+
catalogPath, compareResult, ignoredCatalogEntries);
122118
return compareResult;
123119
}
124120

0 commit comments

Comments
 (0)