Changeset 32524 in osm for applications/editors/josm/plugins/pdfimport/src
- Timestamp:
- 2016-07-02T02:48:15+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/PdfBoxParser.java
r30701 r32524 5 5 import java.awt.geom.Rectangle2D; 6 6 import java.io.File; 7 import java.io.IOException; 7 8 import java.util.List; 8 9 … … 22 23 } 23 24 24 public void parse(File file, int maxPaths, ProgressMonitor monitor) throws Exception 25 { 26 monitor.beginTask(tr("Parsing PDF", 1)); 25 public void parse(File file, int maxPaths, ProgressMonitor monitor) throws IOException { 26 monitor.beginTask(tr("Parsing PDF", 1)); 27 27 28 file);28 try (PDDocument document = PDDocument.load(file)) { 29 29 30 if(document.isEncrypted()){31 32 30 if (document.isEncrypted()) { 31 throw new IllegalArgumentException(tr("Encrypted documents not supported.")); 32 } 33 33 34 34 List<?> allPages = document.getDocumentCatalog().getAllPages(); 35 35 36 if (allPages.size() != 1) { 37 throw new Exception(tr("The PDF file must have exactly one page.")); 38 } 36 if (allPages.size() != 1) { 37 throw new IllegalArgumentException(tr("The PDF file must have exactly one page.")); 38 } 39 40 PDPage page = (PDPage) allPages.get(0); 41 PDRectangle pageSize = page.findMediaBox(); 42 Integer rotationVal = page.getRotation(); 43 int rotation = 0; 44 if (rotationVal != null) { 45 rotation = rotationVal.intValue(); 46 } 47 48 new PageDrawer().drawPage(new GraphicsProcessor(target, rotation, maxPaths, monitor), page); 49 this.target.bounds = new Rectangle2D.Double( 50 pageSize.getLowerLeftX(), 51 pageSize.getLowerLeftY(), 52 pageSize.getWidth(), 53 pageSize.getHeight()); 54 } 39 55 40 PDPage page = (PDPage)allPages.get(0); 41 PDRectangle pageSize = page.findMediaBox(); 42 Integer rotationVal = page.getRotation(); 43 int rotation = 0; 44 if (rotationVal != null){ 45 rotation = rotationVal.intValue(); 46 } 47 48 GraphicsProcessor p = new GraphicsProcessor(target, rotation, maxPaths, monitor); 49 PageDrawer drawer = new PageDrawer(); 50 drawer.drawPage(p, page); 51 this.target.bounds = new Rectangle2D.Double(pageSize.getLowerLeftX(), pageSize.getLowerLeftY(), pageSize.getWidth(), pageSize.getHeight()); 52 53 monitor.finishTask(); 54 } 56 monitor.finishTask(); 57 } 55 58 }
Note:
See TracChangeset
for help on using the changeset viewer.