Public Shared Sub ConvertPDF2Image(ByVal pdfInputPath As String, ByVal imageOutputPath As String, ByVal imageName As String, ByVal startPageNum As Integer, ByVal endPageNum As Integer, ByVal imageFormat As ImageFormat, ByVal resolution As Double)
Dim pdfDoc As Acrobat.CAcroPDDoc = Nothing
Dim pdfPage As Acrobat.CAcroPDPage = Nothing
Dim pdfRect As Acrobat.CAcroRect = Nothing
Dim pdfPoint As Acrobat.CAcroPoint = Nothing
pdfDoc = CType(Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", ""), Acrobat.CAcroPDDoc)
If Not pdfDoc.Open(pdfInputPath) Then
Throw New FileNotFoundException()
End If
If Not Directory.Exists(imageOutputPath) Then
Directory.CreateDirectory(imageOutputPath)
End If
If startPageNum <= 0 Then
startPageNum = 1
End If
If endPageNum > pdfDoc.GetNumPages() OrElse endPageNum <= 0 Then
endPageNum = pdfDoc.GetNumPages()
End If
If startPageNum > endPageNum Then
Dim tempPageNum As Integer = startPageNum
startPageNum = endPageNum
endPageNum = startPageNum
End If
If imageFormat Is Nothing Then
imageFormat = ImageFormat.Jpeg
End If
If resolution <= 0 Then
resolution = 1
End If
For i As Integer = startPageNum To endPageNum
pdfPage = CType(pdfDoc.AcquirePage(i - 1), Acrobat.CAcroPDPage)
pdfPoint = CType(pdfPage.GetSize(), Acrobat.CAcroPoint)
pdfRect = CType(Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.Rect", ""), Acrobat.CAcroRect)
Dim imgWidth As Integer = CInt((CDbl(pdfPoint.x) * resolution))
Dim imgHeight As Integer = CInt((CDbl(pdfPoint.y) * resolution))
pdfRect.Left = 0
pdfRect.right = CShort(imgWidth)
pdfRect.Top = 0
pdfRect.bottom = CShort(imgHeight)
pdfPage.CopyToClipboard(pdfRect, 0, 0, CShort((100 * resolution)))
Dim clipboardData As IDataObject = Clipboard.GetDataObject()
If clipboardData.GetDataPresent(DataFormats.Bitmap) Then
Dim pdfBitmap As Bitmap = CType(clipboardData.GetData(DataFormats.Bitmap), Bitmap)
pdfBitmap.Save(Path.Combine(imageOutputPath, imageName) & ".jpg", imageFormat)
pdfBitmap.Dispose()
End If
Next
pdfDoc.Close()
Marshal.ReleaseComObject(pdfPage)
Marshal.ReleaseComObject(pdfRect)
Marshal.ReleaseComObject(pdfDoc)
Marshal.ReleaseComObject(pdfPoint)
End Sub
到全局代码这步点确定提示:
编译错误:无法加载引用的库”C:\foxtable\Normal\Acrobat.dl”.试图加载格式
不正确的程序。