pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tchoje...@apache.org
Subject svn commit: r1488049 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: pdfwriter/COSWriter.java pdmodel/PDDocument.java
Date Thu, 30 May 2013 23:31:43 GMT
Author: tchojecki
Date: Thu May 30 23:31:43 2013
New Revision: 1488049

URL: http://svn.apache.org/r1488049
Log:
PDFBOX-1613: Add the ability to set the document id for a document before saving.

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1488049&r1=1488048&r2=1488049&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Thu May 30
23:31:43 2013
@@ -1420,7 +1420,10 @@ public class COSWriter implements ICOSVi
      * @throws COSVisitorException If an error occurs while generating the data.
      */
     public void write(PDDocument doc) throws COSVisitorException
-    {
+	{
+        Long idTime = doc.getDocumentId() == null ? System.currentTimeMillis() : 
+                                                    doc.getDocumentId();
+        
         document = doc;
         if(incrementalUpdate)
         {
@@ -1473,7 +1476,7 @@ public class COSWriter implements ICOSVi
                 //algorithm says to use time/path/size/values in doc to generate
                 //the id.  We don't have path or size, so do the best we can
                 MessageDigest md = MessageDigest.getInstance( "MD5" );
-                md.update( Long.toString( System.currentTimeMillis()).getBytes("ISO-8859-1")
);
+                md.update( Long.toString(idTime).getBytes("ISO-8859-1") );
                 COSDictionary info = (COSDictionary)trailer.getDictionaryObject( COSName.INFO
);
                 if( info != null )
                 {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1488049&r1=1488048&r2=1488049&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Thu May 30
23:31:43 2013
@@ -116,6 +116,14 @@ public class PDDocument implements Pagea
      * from this documents.
      */
     private boolean allSecurityToBeRemoved = false;
+
+    /**
+     * Keep tracking customized documentId for the trailer. If null, a new 
+     * id will be generated for the document. This ID doesn't represent the
+     * actual documentId from the trailer.
+     */
+    private Long documentId;
+
     
     /**
      * Constructor, creates a new PDF Document with no pages.  You need to add
@@ -1627,5 +1635,15 @@ public class PDDocument implements Pagea
     {
         allSecurityToBeRemoved = removeAllSecurity;
     }
+    
+    public Long getDocumentId() 
+    {
+      return documentId;
+    }
+    
+    public void setDocumentId(Long docId)
+    {
+      documentId = docId;
+    }
 }
 



Mime
View raw message