An application for you to check the live coordinate of your cursor as you click around in a PDF document. This application is especially useful when you need to know the coordinate in order to put in text or images inside a PDF document. For example, you want to put text to fill up your personal information inside a PDF form, you want to put a logo in a specific position of a PDF document.
New function added to display the coordinate within the Tkinter
window and also now multipage PDF is supported.
The application can be helpful for tools such as PDF-Lib a javascript program to create and modify PDF document. You can use it to get the coordinate that you want to put a text or image component.
You can use a package manager such as npm
to install the program for web development:
npm i --save pdf-lib
Install the required packages:
py -m pip install -r requirements.txt
To run the program, you will then be prompted to input the path of the PDF file:
py pdf_coordinate.py
First of all, we will render a PDF document in a display window. As we move our cursor, information such as the cursor coordinate can then be mapped to the PDF coordinate. With this information, we can then convert this coordinate to a PDF coordinate.
The crucial part is the conversion of canvas coordinates to PDF coordinates. For a canvas coordinate system the origin is at the top-left corner of the canvas. In contrast, the PDF coordinate system has the origin at the bottom-left corner of the PDF page. We can use this formula to convert between the two:
pdf_x = (canvas_x / canvas_width) * page_width
pdf_y = (canvas_height - canvas_y) / canvas_height * page_height
Let
Finally,