設置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 密碼,選擇要掃描的頁面,DPI 來解析 PDF,以及任何額外的縮放以改善讀取質量。

重點

  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剛剛發布