
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
A simple python wrapper for PDFium.
pip install pypdfium
import sys
from PIL import Image
import ctypes
import pypdfium as PDFIUM
PDFIUM.FPDF_InitLibraryWithConfig(PDFIUM.FPDF_LIBRARY_CONFIG(2, None, None, 0))
if __name__ == "__main__":
if len(sys.argv) < 2:
print("USAGE: demo.py somefile.pdf")
exit(0)
fname = sys.argv[1]
doc = PDFIUM.FPDF_LoadDocument(fname, None) # load document
page_count = PDFIUM.FPDF_GetPageCount(doc) # get page counts
assert(page_count >= 1)
page = PDFIUM.FPDF_LoadPage(doc, 0) # load the first page
width = int(PDFIUM.FPDF_GetPageWidthF(page) + 0.5) # get page width
height = int(PDFIUM.FPDF_GetPageHeightF(page) + 0.5) # get page height
# render to bitmap
bitmap = PDFIUM.FPDFBitmap_Create(width, height, 0)
PDFIUM.FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF)
PDFIUM.FPDF_RenderPageBitmap(
bitmap, page, 0, 0, width, height, 0,
PDFIUM.FPDF_LCD_TEXT | PDFIUM.FPDF_ANNOT
)
# retrieve data from bitmap
buffer = PDFIUM.FPDFBitmap_GetBuffer(bitmap)
buffer_ = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_ubyte * (width * height * 4)))
img = Image.frombuffer("RGBA", (width, height), buffer_.contents, "raw", "BGRA", 0, 1)
img.save("out.png")
if bitmap is not None:
PDFIUM.FPDFBitmap_Destroy(bitmap)
PDFIUM.FPDF_ClosePage(page)
PDFIUM.FPDF_CloseDocument(doc)
Working on 64bit Windows, Mac OS X and Linux.
The pypdfium.py
file is generated by ctypesgen with command: ctypesgen -lpdfium -L somewhere/pdfium-linux/lib somewhere/pdfium-linux/include/*.h -o pypdfium.py
PDFium binaries are from https://github.com/bblanchon/pdfium-binaries
API documentation: https://developers.foxitsoftware.com/resources/pdf-sdk/c_api_reference_pdfium/
A PDF manager based on pypdfium: https://github.com/YinlinHu/kuafu
FAQs
A simple python wrapper for PDFium
We found that pypdfium demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.