Read and Write Barcodes with PDF
Published: 2022-02-28 03:54:31

---
canonical_url: https://ironsoftware.com/csharp/barcode/examples/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](https://ironsoftware.com/csharp/barcode/downloads/read-barcode-image-pdf-csharp.zip).

**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
```

**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
```