pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1659643 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: cos/COSDocument.java pdfparser/COSParser.java pdfparser/FDFParser.java pdfparser/PDFParser.java
Date Fri, 13 Feb 2015 18:35:55 GMT
Author: lehmi
Date: Fri Feb 13 18:35:54 2015
New Revision: 1659643

URL: http://svn.apache.org/r1659643
Log:
PDFBOX-2099: remove header string from COSDocument

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=1659643&r1=1659642&r2=1659643&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Fri Feb 13 18:35:54
2015
@@ -71,8 +71,6 @@ public class COSDocument extends COSBase
      */
     private SignatureInterface signatureInterface;
 
-    private String headerString = "%PDF-" + version;
-
     private boolean warnMissingClose = true;
     
     /** 
@@ -255,18 +253,13 @@ public class COSDocument extends COSBase
     }
 
     /**
-     * This will set the version of this PDF document.
+     * This will set the header version of this PDF document.
      *
      * @param versionValue The version of the PDF document.
      */
-    public void setVersion( double versionValue )
+    public void setVersion( float versionValue )
     {
-        // update header string
-        if (versionValue != version) 
-        {
-            headerString = headerString.replaceFirst(String.valueOf(version), String.valueOf(versionValue));
-        }
-        version = (float)versionValue;
+        version = versionValue;
     }
 
     /**
@@ -276,21 +269,6 @@ public class COSDocument extends COSBase
      */
     public float getVersion()
     {
-        if (version < 0)
-        {
-            try
-            {
-                String[] headerParts = headerString.split("-");
-                if (headerParts.length == 2)
-                {
-                    version = Float. parseFloat(headerParts[1]);
-                }
-            }
-            catch ( NumberFormatException e )
-            {
-                version = -1;
-            }
-        }
         return version;
     }
 
@@ -577,23 +555,6 @@ public class COSDocument extends COSBase
     }
 
     /**
-     * @return Returns the headerString.
-     */
-    public String getHeaderString()
-    {
-        return headerString;
-    }
-    /**
-     * @param header The headerString to set.
-     */
-    public void setHeaderString(String header)
-    {
-        headerString = header;
-        // reset version
-        version = -1;
-    }
-
-    /**
      * This method will search the list of objects for types of ObjStm.  If it finds
      * them then it will parse out all of the objects from the stream that is contains.
      *

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java?rev=1659643&r1=1659642&r2=1659643&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java Fri Feb 13
18:35:54 2015
@@ -1176,6 +1176,7 @@ public class COSParser extends BaseParse
                 }
             }
         }
+        // TODO cross check found objects
     }
 
     /**
@@ -1498,9 +1499,6 @@ public class COSParser extends BaseParse
         COSDictionary parsedTrailer = parseCOSDictionary();
         xrefTrailerResolver.setTrailer( parsedTrailer );
     
-        // The version can also be specified within the document /Catalog
-        readVersionInTrailer(parsedTrailer);
-    
         skipSpaces();
         return true;
     }
@@ -1580,54 +1578,30 @@ public class COSParser extends BaseParse
                 pdfSource.unread(headerGarbage.getBytes(ISO_8859_1));
             }
         }
-        document.setHeaderString(header);
+        float headerVersion = -1;
         try
         {
-            if (header.startsWith( headerMarker ))
+            String[] headerParts = header.split("-");
+            if (headerParts.length == 2)
             {
-                float pdfVersion = Float. parseFloat(
-                        header.substring( headerMarker.length(), Math.min( header.length(),
headerMarker.length()+3) ) );
-                document.setVersion( pdfVersion );
+                headerVersion = Float.parseFloat(headerParts[1]);
             }
         }
-        catch ( NumberFormatException e )
+        catch (NumberFormatException exception)
+        {
+            LOG.debug("Can't parse the header version.", exception);
+        }
+        if (headerVersion < 0)
         {
-            throw new IOException( "Error getting version: " + e.getMessage(), e );
+            throw new IOException( "Error getting header version: " + header);
         }
+        document.setVersion(headerVersion);
         // rewind
         pdfSource.seek(0);
         return true;
     }
 
     /**
-     * The document catalog can also have a /Version parameter which overrides the version
specified
-     * in the header if, and only if it is greater.
-     *
-     * @param parsedTrailer the parsed catalog in the trailer
-     */
-    protected void readVersionInTrailer(COSDictionary parsedTrailer)
-    {
-        COSObject root = (COSObject) parsedTrailer.getItem(COSName.ROOT);
-        if (root != null)
-        {
-            COSBase item = root.getItem(COSName.VERSION);
-            if (item instanceof COSName)
-            {
-                COSName version = (COSName) item;
-                float trailerVersion = Float.valueOf(version.getName());
-                if (trailerVersion > document.getVersion())
-                {
-                    document.setVersion(trailerVersion);
-                }
-            }
-            else if (item != null)
-            {
-                LOG.warn("Incorrect /Version entry is ignored: " + item);
-            }
-        }
-    }
-
-    /**
      * This will parse the xref table from the stream and add it to the state
      * The XrefTable contents are ignored.
      * @param startByteOffset the offset to start at

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java?rev=1659643&r1=1659642&r2=1659643&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java Fri Feb 13
18:35:54 2015
@@ -152,9 +152,6 @@ public class FDFParser extends COSParser
         {
             parseDictObjects((COSDictionary) rootObject, (COSName[]) null);
         }
-    
-        // PDFBOX-1922: read the version again now that all objects have been resolved
-        readVersionInTrailer(trailer);
         initialParseDone = true;
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java?rev=1659643&r1=1659642&r2=1659643&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java Fri Feb 13
18:35:54 2015
@@ -346,8 +346,6 @@ public class PDFParser extends COSParser
             parseDictObjects((COSDictionary) catalogObj.getObject(), (COSName[]) null);
             document.setDecrypted();
         }
-        // PDFBOX-1922: read the version again now that all objects have been resolved
-        readVersionInTrailer(trailer);
         initialParseDone = true;
     }
 



Mime
View raw message