Return to Blog Home

Python PDF Binder

 

Python PDF Binder

Merging PDFs for Emailing!

While many applications today are some form of web application, there are still many uses for local applications, and while solutions such as Electron can be used to bring the web to desktop applications, sometimes it's too much - enter for example Python & Tkinter.

Despite the common or plain appearance of un-styled Tkinter applications, they can with a little bit of effort do most of what one would desire of a GUI application.

Problem

The actual application I was to write was solving the issue of PDFs that are commonly used for presentations, where there are a few pages that are unique while the rest are in reality the same, and most PDFs are meant to be shared - which is commonly done via EMail.

My application would allow users to simply combine a number of PDFs into a single PDF, all under a desired filesize to allow for Emailing.

After a bit of research, I found the most efficient size reduction while maintaining as much quality as possible acheivable via a Ghostscript command to reduce the DPI of individual PDF pages. In combination with my script I'd dynamically decrease the DPI of pages that could afford being lower quality until the desired filesize was acheived.

GUI

As I wanted some Drag-And-Drop functionality, I went not only with Tkinter but tkinterdnd2, in addition to controls allowing for file selection, and other QOL improvements such as the ability to reorder PDFs, see the total page count, trim the common prefix of all filenames, customize the desired output PDF size, and finally after generation be told the DPI and final filesize.

Most non-technical users won't have Python on their machines, so with a little help from PyInstaller I was able to nearly seamlessly generate platform-spefic executables from my GUI script.