设置PDF条码阅读器选项
using IronBarCode;

PdfBarcodeReaderOptions myPdfOptionsExample = new PdfBarcodeReaderOptions()
{
    // The password string to open the PDF if there is one
    Password = "password123",

    // Pages of the PDF you want to scan
    PageNumbers = new[] { 1, 3 },

    // By default, all barcode formats are scanned for
    // Specifying a subset of barcode types to search for would improve performance
    ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,

    // The DPI (dots per inch) to render each barcode image for reading
    DPI = 72,

    // The scaling factor to scale the width and height when converting the PDF to image
    // Default is 3.5 for both dimensions
    Scale = 4
};

// Read the pdf with the options applied
var results = BarcodeReader.ReadPdf("barcode.pdf", myPdfOptionsExample);
NuGet下载
PM > Install-Package BarCode
设置PDF条码阅读器选项

设置PDF条码阅读器选项

IronBarcode在PdfBarcodeReaderOptions类中有多种选项来支持PDF的定制和优化读取。 这将处理PDF密码,选择要扫描的页面,选择解析PDF的DPI,以及任何需要的额外缩放以提高读取质量。

关键点

  1. 创建PdfBarcodeReaderOptions:
    • 创建PdfBarcodeReaderOptions的实例来设置各种PDF处理选项:
      • DPI:设置PDF解析的分辨率。 更高的DPI可以提高条形码检测的准确性。
      • PageNumbers:指定应扫描的PDF页面。 这可以自定义以定位特定页面。
      • Password:如果PDF有密码保护,可以使用此选项提供正确的密码。
      • Scale:此选项(默认为3.5)允许调整PDF图像的比例,以帮助提高条形码检测的准确性。
  2. 读取条形码:
    • 使用BarcodeReader.ReadPdf方法从PDF文件中读取和解码条形码。它利用了指定的选项。
  3. 迭代和显示结果:
    • 一个 foreach 循环遍历条形码结果,在控制台显示每个条形码的 Type 和 Value。
    • 这确保从指定页面检测到的所有条码都被输出,以便验证或进一步处理。
学习如何使用 C# 从 PDF 中读取条形码
在GitHub上查看

准备开始了吗?

NuGet 下载量 2,564,559版本:2026.11刚刚发布