Last active
November 19, 2024 19:03
-
-
Save tresf/ec22b6e6767562dfc511188bdc82615e to your computer and use it in GitHub Desktop.
Python PDFBOX Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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(); |
@Nagaraj-P-GDR Hi! You probably want to inquire about this on the PDFBOX mailing list. The Java code and the Python code will be pretty similar once the class has been loaded into jpype1
. This code snippet is a getting started example ,but please feel free to fork the code if you find it helpful.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please check and share a code for structure element tag a PDF for accessibility purpose.