Author: tilman
Date: Wed Oct 12 18:40:31 2016
New Revision: 1764496

URL: http://svn.apache.org/viewvc?rev=1764496&view=rev
Log:
PDFBOX-3530: add option to skip images

Modified:
    
pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/WriteDecodedDoc.java

Modified: 
pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/WriteDecodedDoc.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/WriteDecodedDoc.java?rev=1764496&r1=1764495&r2=1764496&view=diff
==============================================================================
--- 
pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/WriteDecodedDoc.java 
(original)
+++ 
pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/WriteDecodedDoc.java 
Wed Oct 12 18:40:31 2016
@@ -35,6 +35,7 @@ public class WriteDecodedDoc
 {
 
     private static final String PASSWORD = "-password";
+    private static final String SKIPIMAGES = "-skipImages";
 
     /**
      * Constructor.
@@ -50,10 +51,11 @@ public class WriteDecodedDoc
      * @param in The filename used for input.
      * @param out The filename used for output.
      * @param password The password to open the document.
+     * @param skipImages Whether to skip decoding images.
      *
      * @throws IOException if the output could not be written
      */
-    public void doIt(String in, String out, String password)
+    public void doIt(String in, String out, String password, boolean 
skipImages)
             throws IOException
     {
         PDDocument doc = null;
@@ -66,7 +68,13 @@ public class WriteDecodedDoc
                 COSBase base = cosObject.getObject();
                 if (base instanceof COSStream)
                 {
-                    COSStream stream = (COSStream)base;
+                    COSStream stream = (COSStream) base;
+                    if (skipImages &&
+                        COSName.XOBJECT.equals(stream.getItem(COSName.TYPE)) 
&& 
+                        COSName.IMAGE.equals(stream.getItem(COSName.SUBTYPE)))
+                    {
+                        continue;
+                    }
                     byte[] bytes = new PDStream(stream).toByteArray();
                     stream.removeItem(COSName.FILTER);
                     OutputStream streamOut = stream.createOutputStream();
@@ -103,6 +111,7 @@ public class WriteDecodedDoc
         String password = "";
         String pdfFile = null;
         String outputFile = null;
+        boolean skipImages = false;
         for( int i=0; i<args.length; i++ )
         {
             if( args[i].equals( PASSWORD ) )
@@ -114,6 +123,10 @@ public class WriteDecodedDoc
                 }
                 password = args[i];
             }
+            else if (args[i].equals( SKIPIMAGES ))
+            {
+                skipImages = true;
+            }
             else
             {
                 if( pdfFile == null )
@@ -136,7 +149,7 @@ public class WriteDecodedDoc
             {
                 outputFile = calculateOutputFilename(pdfFile);
             }
-            app.doIt(pdfFile, outputFile, password);
+            app.doIt(pdfFile, outputFile, password, skipImages);
         }
     }
 
@@ -163,6 +176,7 @@ public class WriteDecodedDoc
         String message = "Usage: java -jar pdfbox-app-x.y.z.jar 
WriteDecodedDoc [options] <inputfile> [outputfile]\n"
                 + "\nOptions:\n"
                 + "  -password <password> : Password to decrypt the document\n"
+                + "  skipImages           : Don't uncompress images\n"
                 + "  <inputfile>          : The PDF document to be 
decompressed\n"
                 + "  [outputfile]         : The filename for the decompressed 
pdf\n";
        


Reply via email to