pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1791017 - in /pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util: ExtractTextByArea.java PrintImageLocations.java PrintTextColors.java
Date Tue, 11 Apr 2017 19:48:27 GMT
Author: tilman
Date: Tue Apr 11 19:48:27 2017
New Revision: 1791017

URL: http://svn.apache.org/viewvc?rev=1791017&view=rev
Log:
PDFBOX-2852: use JDK7 syntax

Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextColors.java

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java?rev=1791017&r1=1791016&r2=1791017&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java
Tue Apr 11 19:48:27 2017
@@ -20,7 +20,7 @@ import org.apache.pdfbox.pdmodel.PDDocum
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.text.PDFTextStripperByArea;
 
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
 import java.io.File;
 import java.io.IOException;
 
@@ -52,10 +52,8 @@ public final class ExtractTextByArea
         }
         else
         {
-            PDDocument document = null;
-            try
+            try (PDDocument document = PDDocument.load(new File(args[0])))
             {
-                document = PDDocument.load( new File(args[0]) );
                 PDFTextStripperByArea stripper = new PDFTextStripperByArea();
                 stripper.setSortByPosition( true );
                 Rectangle rect = new Rectangle( 10, 280, 275, 60 );
@@ -65,13 +63,6 @@ public final class ExtractTextByArea
                 System.out.println( "Text in the area:" + rect );
                 System.out.println( stripper.getTextForRegion( "class1" ) );
             }
-            finally
-            {
-                if( document != null )
-                {
-                    document.close();
-                }
-            }
         }
     }
 

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java?rev=1791017&r1=1791016&r2=1791017&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java
Tue Apr 11 19:48:27 2017
@@ -75,10 +75,8 @@ public class PrintImageLocations extends
         }
         else
         {
-            PDDocument document = null;
-            try
+            try (PDDocument document = PDDocument.load(new File(args[0])))
             {
-                document = PDDocument.load( new File(args[0]) );
                 PrintImageLocations printer = new PrintImageLocations();
                 int pageNum = 0;
                 for( PDPage page : document.getPages() )
@@ -88,13 +86,6 @@ public class PrintImageLocations extends
                     printer.processPage(page);
                 }
             }
-            finally
-            {
-                if( document != null )
-                {
-                    document.close();
-                }
-            }
         }
     }
 

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextColors.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextColors.java?rev=1791017&r1=1791016&r2=1791017&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextColors.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextColors.java
Tue Apr 11 19:48:27 2017
@@ -87,11 +87,8 @@ public class PrintTextColors extends PDF
         }
         else
         {
-            PDDocument document = null;
-            try
+            try (PDDocument document = PDDocument.load(new File(args[0])))
             {
-                document = PDDocument.load(new File(args[0]));
-
                 PDFTextStripper stripper = new PrintTextColors();
                 stripper.setSortByPosition(true);
                 stripper.setStartPage(0);
@@ -100,13 +97,6 @@ public class PrintTextColors extends PDF
                 Writer dummy = new OutputStreamWriter(new ByteArrayOutputStream());
                 stripper.writeText(document, dummy);
             }
-            finally
-            {
-                if (document != null)
-                {
-                    document.close();
-                }
-            }
         }
     }
 



Mime
View raw message