2014-10-01 216 views
0

我只是想知道是否有人有閱讀PDF文件中的條形碼的經驗。我GOOGLE了,發現這個bytescout閱讀器,並使用這樣的程序從pdf讀取條碼

Reader barcodeReader = new Reader(); 
barcodeReader.BarcodeTypesToFind.Code39 = true; 
Console.WriteLine("Reading barcode(s) from PDF"); 

FoundBarcode[] barcodes = barcodeReader.ReadFrom("Sample.pdf"); 

foreach (FoundBarcode barcode in barcodes) 
    Console.WriteLine("Found barcode with type '{0}' and value '{1}'", barcode.Type, barcode.Value); 

這不輸出任何條形碼。 請推薦我可以使用的任何其他圖書館?

回答

3

DataMatrix是一個C#庫,可以解碼圖像文件中的條形碼,我相信它也可以從PDF中讀取它們。下面是一個使用示例:

private string DecodeText(string sFileName) 
{ 
    DmtxImageDecoder decoder = new DmtxImageDecoder(); 
    System.Drawing.Bitmap oBitmap = new System.Drawing.Bitmap(sFileName); 
    List<string> oList = decoder.DecodeImage(oBitmap); 

    StringBuilder sb = new StringBuilder(); 
    sb.Length = 0; 
    foreach (string s in oList) 
    { 
     sb.Append(s); 
    } 
    return sb.ToString(); 
} 

您傳入一個圖像文件名,它將解碼條形碼並返回字符串。如果DataMatrix沒有讀取PDF文件,那麼您還必須下載iTextSharp這是一個操作PDF的庫。使用iTextSharp,您可以從PDF中提取條形碼,將其保存爲圖像,然後使用上述功能解釋條形碼。