Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/619445804772930b66008ece57a69897 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/619445804772930b66008ece57a69897 to your computer and use it in GitHub Desktop.
How to Read Barcode from PDF in Python
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