You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/04/03 17:46:59 UTC
svn commit: r1856891 - in
/pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox:
pdfwriter/COSWriter.java pdmodel/PDDocument.java
Author: tilman
Date: Wed Apr 3 17:46:59 2019
New Revision: 1856891
URL: http://svn.apache.org/viewvc?rev=1856891&view=rev
Log:
PDFBOX-45: allow incremental save with chosen objects to update these for sure
Modified:
pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
Modified: pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1856891&r1=1856890&r2=1856891&view=diff
==============================================================================
--- pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Wed Apr 3 17:46:59 2019
@@ -251,6 +251,24 @@ public class COSWriter implements ICOSVi
incrementalUpdate = true;
}
+ /**
+ * COSWriter constructor for incremental updates with a list of objects to write. This allows to
+ * include objects even if there is no path of objects that have
+ * {@link COSUpdateInfo#isNeedToBeUpdated()} set. This makes the update smaller.
+ *
+ * @param outputStream output stream where the new PDF data will be written. It will be closed
+ * when this object is closed.
+ * @param inputData random access read containing source PDF data.
+ * @param objectsToWrite objects that <b>must</b> be part of the incremental saving.
+ * @throws IOException if something went wrong
+ */
+ public COSWriter(OutputStream outputStream, RandomAccessRead inputData,
+ List<COSBase> objectsToWrite) throws IOException
+ {
+ this(outputStream, inputData);
+ this.objectsToWrite.addAll(objectsToWrite);
+ }
+
private void prepareIncrement(PDDocument doc)
{
try
Modified: pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1856891&r1=1856890&r2=1856891&view=diff
==============================================================================
--- pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Wed Apr 3 17:46:59 2019
@@ -1370,6 +1370,43 @@ public class PDDocument implements Close
}
/**
+ * Save the PDF as an incremental update. This is only possible if the PDF was loaded from a
+ * file or a stream, not if the document was created in PDFBox itself. This allows to include
+ * objects even if there is no path of objects that have
+ * {@link COSUpdateInfo#isNeedToBeUpdated()} set. This makes the update smaller.
+ *
+ * @param output stream to write to. It will be closed when done. It
+ * <i><b>must never</b></i> point to the source file or that one will be harmed!
+ * @param objectsToWrite objects that <b>must</b> be part of the incremental saving.
+ * @throws IOException if the output could not be written
+ * @throws IllegalStateException if the document was not loaded from a file or a stream.
+ */
+ public void saveIncremental(OutputStream output, List<COSBase> objectsToWrite) throws IOException
+ {
+ if (pdfSource == null)
+ {
+ throw new IllegalStateException("document was not loaded from a file or a stream");
+ }
+ COSWriter writer = null;
+ try
+ {
+ if (pdfSource == null)
+ {
+ throw new IllegalStateException("document was not loaded from a file or a stream");
+ }
+ writer = new COSWriter(output, pdfSource, objectsToWrite);
+ writer.write(this, signInterface);
+ }
+ finally
+ {
+ if (writer != null)
+ {
+ writer.close();
+ }
+ }
+ }
+
+ /**
* <p>
* <b>(This is a new feature for 2.0.3. The API for external signing might change based on feedback after release!)</b>
* <p>