I have one now.Pdf
Documents, adoptedPDFBox
Rendered as one picture per page
// load pdf and save image
try (PDDocument document = PDDocument.load("some file")) {
PDFRenderer render = new PDFRenderer(document);
BufferedImage scaledImage = render.renderImageWithDPI(pageIndex, 326);
// save image
bracket
The saved picture in this step will be previewed in the browser. Users can drag and drop the picture into this preview picture, and then I will map this coordinate to the real one.Pdf
However, there are always some errors. The following is my mapping method:
- Gets the preview map in the browser’s
width,height
Gets the in the upper-left corner of the preview of the drag-and-drop picture.x,y
- Back-end acquisition
Pdf
Actualwidth,height
, and then calculate and preview theWide ratioIn the endDrag and drop picturesIn PDFThe upper left cornerThex,y
-
Because the origin of coordinates in the PDF is the lower left corner of the document, the final
x,y
The calculation formula is:- x: float targetX = (previewX1.0F / previewWidth)pdfPageWidth;
- y: float targetY = pdfPageHeight – (previewY1.0F / previewHeight)pdfPageHeight – dragImageHeight
- According to the calculation in the previous step
x,y
This figure is drawn in the PDF on this page, but there are errors, and the errors are obvious.What should I do?
Reference document
The problem has puzzled week. The problem has finally been solved. The algorithm itself has no problem. Only the third-party system will zoom the target image. The calculation will be accurate when the zoom ratio is added.