Index: /applications/editors/josm/plugins/pdfimport/.classpath
===================================================================
--- /applications/editors/josm/plugins/pdfimport/.classpath	(revision 32523)
+++ /applications/editors/josm/plugins/pdfimport/.classpath	(revision 32524)
@@ -3,4 +3,5 @@
 	<classpathentry kind="src" path="src"/>
 	<classpathentry kind="src" path="resources"/>
+	<classpathentry kind="src" path="test/unit"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
@@ -8,4 +9,5 @@
 	<classpathentry kind="lib" path="lib/jempbox-1.8.12.jar"/>
 	<classpathentry kind="lib" path="lib/pdfbox-1.8.12.jar"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
Index: /applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/PdfBoxParser.java
===================================================================
--- /applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/PdfBoxParser.java	(revision 32523)
+++ /applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/PdfBoxParser.java	(revision 32524)
@@ -5,4 +5,5 @@
 import java.awt.geom.Rectangle2D;
 import java.io.File;
+import java.io.IOException;
 import java.util.List;
 
@@ -22,34 +23,36 @@
 	}
 
-	public void parse(File file, int maxPaths, ProgressMonitor monitor) throws Exception
-	{
-		monitor.beginTask(tr("Parsing PDF", 1));
+    public void parse(File file, int maxPaths, ProgressMonitor monitor) throws IOException {
+        monitor.beginTask(tr("Parsing PDF", 1));
 
-		PDDocument document = PDDocument.load( file);
+        try (PDDocument document = PDDocument.load(file)) {
 
-		if( document.isEncrypted() ){
-			throw new Exception(tr("Encrypted documents not supported."));
-		}
+            if (document.isEncrypted()) {
+                throw new IllegalArgumentException(tr("Encrypted documents not supported."));
+            }
 
-		List<?> allPages = document.getDocumentCatalog().getAllPages();
+            List<?> allPages = document.getDocumentCatalog().getAllPages();
 
-		if (allPages.size() != 1) {
-			throw new Exception(tr("The PDF file must have exactly one page."));
-		}
+            if (allPages.size() != 1) {
+                throw new IllegalArgumentException(tr("The PDF file must have exactly one page."));
+            }
+            
+            PDPage page = (PDPage) allPages.get(0);
+            PDRectangle pageSize = page.findMediaBox();
+            Integer rotationVal = page.getRotation();
+            int rotation = 0;
+            if (rotationVal != null) {
+                rotation = rotationVal.intValue();
+            }
+    
+            new PageDrawer().drawPage(new GraphicsProcessor(target, rotation, maxPaths, monitor), page);
+            this.target.bounds = new Rectangle2D.Double(
+                    pageSize.getLowerLeftX(),
+                    pageSize.getLowerLeftY(), 
+                    pageSize.getWidth(), 
+                    pageSize.getHeight());
+        }
 
-		PDPage page = (PDPage)allPages.get(0);
-		PDRectangle pageSize = page.findMediaBox();
-		Integer rotationVal = page.getRotation();
-		int rotation = 0;
-		if (rotationVal != null){
-			rotation = rotationVal.intValue();
-		}
-
-		GraphicsProcessor p = new GraphicsProcessor(target, rotation, maxPaths, monitor);
-		PageDrawer drawer = new PageDrawer();
-		drawer.drawPage(p, page);
-		this.target.bounds = new Rectangle2D.Double(pageSize.getLowerLeftX(), pageSize.getLowerLeftY(), pageSize.getWidth(), pageSize.getHeight());
-
-		monitor.finishTask();
-	}
+        monitor.finishTask();
+    }
 }
Index: /applications/editors/josm/plugins/pdfimport/test/unit/pdfimport/pdfbox/PDFParserTest.java
===================================================================
--- /applications/editors/josm/plugins/pdfimport/test/unit/pdfimport/pdfbox/PDFParserTest.java	(revision 32524)
+++ /applications/editors/josm/plugins/pdfimport/test/unit/pdfimport/pdfbox/PDFParserTest.java	(revision 32524)
@@ -0,0 +1,41 @@
+package pdfimport.pdfbox;
+
+import static org.junit.Assert.assertEquals;
+
+import java.awt.Rectangle;
+import java.io.File;
+
+import org.junit.Test;
+import org.openstreetmap.josm.TestUtils;
+import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
+
+import pdfimport.PathOptimizer;
+
+public class PDFParserTest {
+
+    private PathOptimizer parse(String fileName) throws Exception {
+        PathOptimizer data = new PathOptimizer(0.0, null, false);
+        PdfBoxParser parser = new PdfBoxParser(data);
+        parser.parse(new File(fileName), Integer.MAX_VALUE, NullProgressMonitor.INSTANCE);
+        return data;
+    }
+
+    @Test
+    public void testParse9053() throws Exception {
+        PathOptimizer data = parse(TestUtils.getRegressionDataFile(9053, "testpdf.pdf"));
+        assertEquals(0, data.bounds.getMinX(), 0);
+        assertEquals(0, data.bounds.getMinY(), 0);
+        assertEquals(595.27557, data.bounds.getMaxX(), 0.00001);
+        assertEquals(841.88977, data.bounds.getMaxY(), 0.00001);
+        assertEquals(4, data.uniquePoints.size());
+        assertEquals(1, data.getLayers().size());
+    }
+
+    @Test
+    public void testParse12176() throws Exception {
+        PathOptimizer data = parse(TestUtils.getRegressionDataFile(12176, "LYD_Etage_0.pdf"));
+        assertEquals(new Rectangle(595, 842), data.bounds);
+        assertEquals(127300, data.uniquePoints.size());
+        assertEquals(34, data.getLayers().size());
+    }
+}
