Am 31.03.2015 um 04:47 schrieb Andrew Munn:
I render docs like this at 720dpi:
BufferedImage bim = pdfRenderer.renderImageWithDPI(pageNum, 720,
ImageType.GRAY);
This way I can measure out fields' locations and sizes in forms using an
image editor in pixels and divide by 10 to get points (72 points per
inch).
I can pull out text like this:
String textFromBox(PDDocument doc, int x, int y, int w, int h, int page){
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
Rectangle rect = new Rectangle(x/10, y/10, w/10, h/10);
stripper.addRegion("region", rect);
System.out.println("getting fom page "+page);
PDPage pp = (PDPage) doc.getDocumentCatalog().getPages().get(page);
stripper.extractRegions(pp);
String text = stripper.getTextForRegion("region");
System.out.println("text=" + text);
return text;
}
Seems to work ok, but I want to overlay some drawn boxes on the form so
I can see easily what in in the fields created. Like this:
http://www.topazdevelopment.com/tmp/annotated.pdf
When I plot the boxes it starts from the bottom-left, not top-left so I
have to flip the y-axis approx like this:
int flip(int x){
// 11" x 72ppi = 792 but 772 works better
return 772-x;
}
cos.addRect(xposition / 10, flip(yposition / 10), width / 10, height / 10);
This method is working somewhat but not exactly. The drawn boxes are
ending up in the wrong place even though I've measured their pixel
position correctly in the rendered image. Is there a better way to
accomplish this?
Yes, play with the CTM (current transformation matrix)... use
transform() and set a ctm that flips... btw, flipping is multiplying
with -1 then adding.
Can I interogate a doc for its height in points?
PDPage.getMediaBox()
Tilman
Thanks!
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org