設置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 Download
PM > Install-Package BarCode
設置PDF條碼讀取器選項

設置PDF條碼讀取器選項

IronBarcode在PdfBarcodeReaderOptions類別中提供多種選項,以支援PDF的客製化和最佳化讀取。 這將處理PDF的密碼、選擇要掃描的頁面、在Dpi中解析PDF的過程,以及任何需要的額外縮放以改善讀取品質。

關鍵要點

  1. 建立PdfBarcodeReaderOptions:
    • 建立PdfBarcodeReaderOptions的實例以設置PDF處理的各種選項:
      • Dpi:設置PDF解析的解析度。 較高的Dpi可以提高條碼檢測的準確性。
      • PageNumbers:指定要掃描的PDF頁面。 這可以客製化以針對特定頁面。
      • Password:如果PDF受到密碼保護,可以使用此選項提供正確的密碼。
      • ScaleToY:這些選項允許調整PDF圖像的比例,以幫助增強條碼檢測的準確性。
  2. 讀取條碼:
    • 使用ReadPdfBarcodes方法從PDF文件中讀取和解碼條碼。它使用所指定的選項。
  3. 遍歷和顯示結果:
    • Value。
    • 這確保所有從指定頁面檢測的條碼都能被輸出以進行驗證或進一步處理。
了解如何使用C#從PDF中讀取條碼
在 GitHub 上查看

準備好開始了嗎?

Nuget Downloads 2,540,041版本:2026.11剛剛發布