zooui.converters.pdfconverter module¶
PDF rasterizer based upon either Xpdf or Poppler.
- class zooui.converters.pdfconverter._DummyFont[source]¶
Bases:
objectSentinel used when PIL is not available for page numbering.
- class zooui.converters.pdfconverter.PDFConverter(infile, outdir, page_numbering=True)[source]¶
Bases:
Converter- Constructor :
PDFConverter(infile, outdir, page_numbering)
- Parameters :
infile : str outdir : str page_numbering : bool (default=True)
PDFConverter(infile, outdir, page_numbering) –> None
PDFConverter objects are used for rasterizing PDFs to per-page PPM files.
Each page is rasterized as a separate PPM file in the output directory:
outdir/page_0000.ppm,outdir/page_0001.ppm, etc.If
page_numberingis True (default), a page number label ("N / total") is drawn onto each PPM image in the bottom-right corner before copying to the output directory.The output format will always be PPM irrespective of the file extension of the output file. If another output format is required then
PDFConvertershould be used in conjunction withVipsConverter.- Constructor :
PDFConverter(infile, outdir, page_numbering)
- Parameters :
infile : str outdir : str page_numbering : bool (default=True)
PDFConverter(infile, outdir, page_numbering) –> None
Create a new PDFConverter for rasterizing PDF files.
The infile parameter is the path to the source PDF file. The outdir parameter is the directory where per-page PPM files will be written. The default resolution is 300 DPI.
If page_numbering is True, each page PPM will have a
"N / total"label drawn in the bottom-right corner.- static _load_page_number_font(font_size)[source]¶
Load a font for drawing page numbers, falling back gracefully.
Tries common system TrueType fonts first, then falls back to PIL’s built-in default bitmap font.
- _draw_page_numbers(tmpdir, page_files)[source]¶
Draw
"N / total"labels onto each page PPM in-place.- Parameters:
tmpdir – Directory containing raw pdftoppm output.
page_files – Mapping of 1-based page number → filename in tmpdir.
- run()[source]¶
- Method :
PDFConverter.run()
- Parameters :
None
PDFConverter.run() –> None
Run the PDF conversion using pdftoppm. Creates a temporary directory, calls pdftoppm to rasterize the PDF into individual PPM pages, then copies each page to the output directory with predictable filenames.
If page_numbering is True, a
"N / total"label is drawn onto each page PPM before copying.If any errors are encountered then
self.errorwill be set to a string describing the error.