PDFHelper Module¶
Provides utilities for handling, reading, and writing PDF files.
- HMB.PDFHelper.ReadFullPDF(filePath)[source]¶
Reads the full content of a PDF file and returns it as a string.
- HMB.PDFHelper.ReadPDFPage(filePath, pageNum)[source]¶
Reads the content of a specific page in a PDF file.
- HMB.PDFHelper.ExtractPDFTextByRegex(filePath, pattern)[source]¶
Extracts all text matching a regex pattern from a PDF file.
- HMB.PDFHelper.ExtractPDFTables(filePath, pages='all')[source]¶
Extracts tables from a PDF file using tabula-py.
- Installation:
Use pip install tabula-py to install the library. Use pip install jpype1 to install the JPype1 dependency. Also requires Java to be installed on the system. Install it from https://www.oracle.com/java/technologies/downloads/
- HMB.PDFHelper.SplitPDF(filePath, startPage, endPage, outputPath)[source]¶
Saves a range of pages from a PDF file as a new PDF.
- HMB.PDFHelper.DeletePDFPages(filePath, pagesToDelete, outputPath)[source]¶
Deletes specified pages from a PDF and saves the result.
- HMB.PDFHelper.RotatePDFPages(filePath, rotation, outputPath, pages=None)[source]¶
Rotates specified pages in a PDF by a given angle.
- HMB.PDFHelper.ExtractPDFAnnotations(filePath)[source]¶
Extracts annotations/comments from all pages of a PDF file.
- HMB.PDFHelper.PDFContainsText(filePath, searchText, caseSensitive=False, useRegex=False, returnPositions=False)[source]¶
Checks if the PDF contains the specified text, with options for case sensitivity, regex, and returning positions.
- Parameters:
filePath (str) – Path to the PDF file.
searchText (str) – Text or regex pattern to search for.
caseSensitive (bool) – If True, search is case sensitive.
useRegex (bool) – If True, searchText is treated as a regex pattern.
returnPositions (bool) – If True, returns list of (pageNum, position) for all occurrences.
- Returns:
True/False if found (default), or list of (pageNum, position) if returnPositions is True.
- Return type:
- HMB.PDFHelper.AddPDFBookmark(filePath, pageNum, title, outputPath)[source]¶
Adds a bookmark to a specific page in the PDF.
- HMB.PDFHelper.HighlightPDFText(filePath, searchText, outputPath, color=(1, 1, 0))[source]¶
Highlights all occurrences of a text string in the PDF.