Skip to content

Instantly share code, notes, and snippets.

@tresf
Last active September 27, 2022 04:14
Show Gist options
  • Save tresf/ec22b6e6767562dfc511188bdc82615e to your computer and use it in GitHub Desktop.
Save tresf/ec22b6e6767562dfc511188bdc82615e to your computer and use it in GitHub Desktop.
Python PDFBOX Example
# Hello PDFBOX - A suprisingly simple example for calling PDFBOX from Python
#
# Author: Tres Finocchiaro
# License: WTFPL
# STEPS:
# macOS:
# brew install python openjdk@11
# pip3 install jpype1
#
# ubuntu:
# sudo apt-get install openjdk-11-jdk pip
# pip install jpype1
#
# windows:
# (help wanted: fork this gist and tag me <3)
import jpype
import jpype.imports
# pdfbox-app-2.x.x.jar is located at ./jars/
jpype.startJVM(classpath = ['jars/*'])
from org.apache.pdfbox.pdmodel import PDDocument, PDPage;
with PDDocument() as document:
# Create a new blank page and add it to the document
blankPage = PDPage();
document.addPage(blankPage );
# Save the newly created document
document.save("BlankPage.pdf");
# Make sure that the document is properly closed.
document.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment