Advertisement
Guest User

ParsePDPaths

a guest
Jun 21st, 2016
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import org.apache.pdfbox.pdmodel.PDDocument;
  2. import org.apache.pdfbox.pdmodel.PDPage;
  3.  
  4. import java.io.File;
  5. import java.io.IOException;
  6.  
  7. public class ParsePDPaths {
  8.  
  9.     public static void main(String[] args) throws IOException{
  10.         String loc="src/test/resources/pg_0005.pdf";
  11.         PDDocument document = PDDocument.load(new File(loc));
  12.         PDPage page = document.getPage(0);
  13.         LinePathFinder finder = new LinePathFinder(page);
  14.         finder.findLinePaths();
  15.         int linePaths=0;
  16.         int curvePaths=0;
  17.         int rectangles=0;
  18.         for (Path p:finder.paths){
  19.             for (SubPath sp: p.subPaths){
  20.                 if (sp instanceof Rectangle)
  21.                     rectangles+=1;
  22.                 else {
  23.                     for (Segment s : sp.segments) {
  24.                         if (s instanceof Line) {
  25.                             linePaths += 1;
  26.                         } else if (s instanceof Curve) {
  27.                             curvePaths += 1;
  28.                         }
  29.                         else {
  30.                             System.out.println(s.getClass());
  31.                         }
  32.                     }
  33.                 }
  34.  
  35.             }
  36.         }
  37.         System.out.println(linePaths+" "+curvePaths+" "+rectangles);
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement