使用GdPicture.NET(点击进入下载页)可以快速读取PDF文档中的1D和2D码,下面给出示例代码。
1 读取PDF文档中的1D码
'Step1: Open the PDF
Dim oGdPicturePDF As New GdPicture.GdPicturePDF
If oGdPicturePDF.LoadFromFile("c:\test.pdf", False) = GdPictureStatus.OK Then
'Step2: Convert the desired PDF page to GdPicture Image
oGdPicturePDF.SelectPage(1)
Dim ImageID As Integer = oGdPicturePDF.RenderPageToGdPictureImage(200, False)
If ImageID <> 0 Then
'Step3: Barcode recognition from GdPicture Image
Dim oGdPictureImaging As New GdPicture.GdPictureImaging
oGdPictureImaging.Barcode1DReaderDoScan(ImageID, Barcode1DReaderScanMode.BestQuality)
oGdPictureImaging.ReleaseGdPictureImage(ImageID)
For i As Integer = 1 To oGdPictureImaging.Barcode1DReaderGetBarcodeCount
MsgBox("Barcode no: " + Str(i) + Chr(13) + _
"Barcode type: " + oGdPictureImaging.Barcode1DReaderGetBarcodeType(i).ToString + Chr(13) + _
"Barcode angle: " + Str(oGdPictureImaging.Barcode1DReaderGetBarcodeSkewAngle(i)) + Chr(13) + _
"Barcode value: " + oGdPictureImaging.Barcode1DReaderGetBarcodeValue(i))
Next
oGdPictureImaging.Barcode1DReaderClear()
oGdPictureImaging.Dispose()
End If
oGdPicturePDF.CloseDocument()
End If
2 读取
PDF文档中的Datamatrix码
'Step1: Open the PDF
Dim oGdPicturePDF As New GdPicture.GdPicturePDF
If oGdPicturePDF.LoadFromFile("c:\test.pdf", False) = GdPictureStatus.OK Then
'Step2: Convert the desired PDF page to GdPicture Image
oGdPicturePDF.SelectPage(1)
Dim ImageID As Integer = oGdPicturePDF.RenderPageToGdPictureImage(200, False)
If ImageID <> 0 Then
'Step3: Barcode recognition from GdPicture Image
Dim oGdPictureImaging As New GdPicture.GdPictureImaging
oGdPictureImaging.BarcodeDataMatrixReaderDoScan(ImageID, BarcodeDataMatrixReaderScanMode.BestQuality)
oGdPictureImaging.ReleaseGdPictureImage(ImageID)
For i As Integer = 1 To oGdPictureImaging.BarcodeDataMatrixReaderGetBarcodeCount
MsgBox("Barcode no: " + Str(i) + Chr(13) + _
"Barcode columns: " + oGdPictureImaging.BarcodeDataMatrixReaderGetBarcodeColumns(i).ToString + Chr(13) + _
"Barcode rows: " + Str(oGdPictureImaging.BarcodeDataMatrixReaderGetBarcodeRows(i)) + Chr(13) + _
"Barcode value: " + oGdPictureImaging.BarcodeDataMatrixReaderGetBarcodeValue(i))
Next
oGdPictureImaging.BarcodeDataMatrixReaderClear()
oGdPictureImaging.Dispose()
End If
oGdPicturePDF.CloseDocument()
End If