DEV Community

IronSoftware
IronSoftware

Posted on • Originally published at ironsoftware.com

1 1

Read and Write Barcodes with PDF

Iron Barcode is proficient in reading barcodes from one or all pages of a PDF document, and those pages can be easily specified. It can also correct for badly scanned PDFs with perhaps skew or digital noise within their image. This can be set specifically by the developer, or automated using the QuicklyReadAllBarcodes method with the TryHarder flag set to true.

We may also add barcodes to a PDF document using the StampToExistingPdfPage method, or simply save our barcode as a standalone PDF file.

You can download the software product from this link.

C#:

using IronBarCode;


/*** READ BARCODES FROM A PDF DOCUMENT ***/

// A PDF document may be easily scanned for 1 or multiple Barcodes
BarcodeResult[] PDFResults = BarcodeReader.QuicklyReadAllBarcodes("MultipleBarcodes.pdf", BarcodeEncoding.AllOneDimensional, true);

// Read only a specific barcode type
BarcodeResult[] InvoiceResults = BarcodeReader.ReadBarcodesFromPdf("PileofInvoices.pdf", BarcodeEncoding.Code128);

// Read only specific pages
PagedBarcodeResult[] InvoiceResultsPage123 = BarcodeReader.ReadBarcodesFromPdfPages("PileofInvoices.pdf", new[] { 1, 2, 3 }, BarcodeEncoding.Code128);

// Read even from badly scanned or noisy PDFs
PagedBarcodeResult[] InvoiceResultsCorrected = BarcodeReader.ReadBarcodesFromPdfPages("PileofInvoices.BadScan.pdf", new[] { 1, 2, 3 }, BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.CleanNonBlackPixels);


/*** WRITE BARCODES TO A NEW OR EXISTING PDF DOCUMENT ***/

GeneratedBarcode MyBarCode = BarcodeWriter.CreateBarcode("1234567890", BarcodeWriterEncoding.Code128);

// Save to a new PDF
MyBarCode.SaveAsPdf("MyBarCode.Pdf");

/// Add the barcode to any page or pages of an existing PDF
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 200, 50, 1);  // position x=200 y=50 on page 1
MyBarCode.StampToExistingPdfPages("ExistingPDF.pdf", 200, 50, new[] { 1, 2, 3 }, "Password123");  // multiple pages of an encrypted PDF
Enter fullscreen mode Exit fullscreen mode

VB:

Imports IronBarCode


'''* READ BARCODES FROM A PDF DOCUMENT **

' A PDF document may be easily scanned for 1 or multiple Barcodes
Private PDFResults() As BarcodeResult = BarcodeReader.QuicklyReadAllBarcodes("MultipleBarcodes.pdf", BarcodeEncoding.AllOneDimensional, True)

' Read only a specific barcode type
Private InvoiceResults() As BarcodeResult = BarcodeReader.ReadBarcodesFromPdf("PileofInvoices.pdf", BarcodeEncoding.Code128)

' Read only specific pages
Private InvoiceResultsPage123() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromPdfPages("PileofInvoices.pdf", { 1, 2, 3 }, BarcodeEncoding.Code128)

' Read even from badly scanned or noisy PDFs
Private InvoiceResultsCorrected() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromPdfPages("PileofInvoices.BadScan.pdf", { 1, 2, 3 }, BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.CleanNonBlackPixels)


'''* WRITE BARCODES TO A NEW OR EXISTING PDF DOCUMENT **

Private MyBarCode As GeneratedBarcode = BarcodeWriter.CreateBarcode("1234567890", BarcodeWriterEncoding.Code128)

' Save to a new PDF
MyBarCode.SaveAsPdf("MyBarCode.Pdf")

''' Add the barcode to any page or pages of an existing PDF
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 200, 50, 1) ' position x=200 y=50 on page 1
MyBarCode.StampToExistingPdfPages("ExistingPDF.pdf", 200, 50, { 1, 2, 3 }, "Password123") ' multiple pages of an encrypted PDF
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay