pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1734615 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXRefStream.java
Date Fri, 11 Mar 2016 18:49:54 GMT
Author: lehmi
Date: Fri Mar 11 18:49:54 2016
New Revision: 1734615

URL: http://svn.apache.org/viewvc?rev=1734615&view=rev
Log:
PDFBOX-3263: create correct cross reference stream

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXRefStream.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXRefStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXRefStream.java?rev=1734615&r1=1734614&r2=1734615&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXRefStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXRefStream.java Fri Mar
11 18:49:54 2016
@@ -77,7 +77,8 @@ public class PDFXRefStream implements PD
         {
             throw new IllegalArgumentException("size is not set in xrefstream");
         }
-        stream.setLong(COSName.SIZE, getSizeEntry());
+        // add one for object number 0
+        stream.setLong(COSName.SIZE, streamData.size() + 1);
     
         List<Long> indexEntry = getIndexEntry();
         COSArray indexAsArray = new COSArray();
@@ -212,11 +213,6 @@ public class PDFXRefStream implements PD
         return w;
     }
 
-    private long getSizeEntry()
-    {
-        return size;
-    }
-
     /**
      * Set the size of the XRef stream.
      * 
@@ -232,8 +228,11 @@ public class PDFXRefStream implements PD
         LinkedList<Long> linkedList = new LinkedList<Long>();
         Long first = null;
         Long length = null;
-
-        for ( Long objNumber : objectNumbers )
+        Set<Long> objNumbers = new TreeSet<Long>();
+        // add object number 0 to the set
+        objNumbers.add(0L);
+        objNumbers.addAll(objectNumbers);
+        for ( Long objNumber : objNumbers )
         {
             if (first == null)
             {
@@ -275,6 +274,10 @@ public class PDFXRefStream implements PD
 
     private void writeStreamData(OutputStream os, int[] w) throws IOException
     {
+        // write dummy entry for object number 0
+        writeNumber(os, ENTRY_FREE, w[0]);
+        writeNumber(os, ENTRY_FREE, w[1]);
+        writeNumber(os, 0xFFFF, w[2]);
         // iterate over all streamData and write it in the required format
         for ( Object entry : streamData.values() )
         {



Mime
View raw message