Created
April 4, 2026 10:24
-
-
Save aspose-com-gists/619445804772930b66008ece57a69897 to your computer and use it in GitHub Desktop.
How to Read Barcode from PDF in Python
This file contains hidden or 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
| import asposebarcode as barcode | |
| import aspose.pdf as pdf | |
| def read_barcodes_from_pdf(pdf_path): | |
| # Load PDF document | |
| pdf_doc = pdf.PdfDocument(pdf_path) | |
| # Initialize barcode reader | |
| reader = barcode.BarcodeReader() | |
| reader.decode_type = barcode.DecodeType.ALL_SUPPORTED_TYPES | |
| # Optional: limit pages for large PDFs | |
| # reader.read_pdf_page_range = (1, 5) | |
| # Read barcodes | |
| for result in reader.read(pdf_doc): | |
| print(f"Page {result.page_number}: {result.barcode_text}") | |
| # Cleanup | |
| pdf_doc.close() | |
| if __name__ == "__main__": | |
| input_pdf = "sample.pdf" | |
| read_barcodes_from_pdf(input_pdf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment