Skip to content
Advertisement

How to make zoom in PDF viewer with Python tkinter and tkPDFViewer?

I have made a very simple PDF viewer for all PDF files contained in the folder where the executable is placed. Then, I am interested in adding some basic utilities to a buttons panel, such as with zoom + and zoom – button to increase the view of PDF file and allowing to improve the reading of the selected PDF file.

Here’s my code [ https://github.com/marco-rosso-m/GUI_simplePDFviewer ]:

JavaScript

Moreover, at present, the above-implemented PDF viewer seems to not be responsive with respect to the window dimension, is any way to make it responsive?

Advertisement

Answer

In order to manage the zooming with tkPDFViewer module, I have downloaded the source code here, then I modified the pdf_view function adding a zooming parameter that I called zoomDPI, setting its default value of 72dpi:

JavaScript

Thereafter, the new input parameter is used to modify the method getPixmap() inside the function add_img(). Inside this function I modified the following line inserting the new input parameter which govern the resolution of the image and thus the zooming level:

JavaScript

Finally, inside the main code, when calling the pdf_view method I can adjust the image level by giving in input a dpi value higher of 72 in order to increase the zoom level (zooming in), or a lower value in order to decrease the zoom level (zooming out).

JavaScript

The new complete code can be found here.

Advertisement