Public Enum Definition
One = 1
Two = 2
Three = 3
Four = 4
Five = 5
Six = 6
Seven = 7
Eight = 8
Nine = 9
Ten = 10
End Enum
''' <summary>
''' 将PDF文档转换为图片的方法
''' </summary>
''' <param name="pdfInputPath">PDF文件路径</param>
''' <param name="imageOutputPath">图片输出路径</param>
''' <param name="imageName">生成图片的名字</param>
''' <param name="startPageNum">从PDF文档的第几页开始转换</param>
''' <param name="endPageNum">从PDF文档的第几页开始停止转换</param>
''' <param name="imageFormat">设置所需图片格式</param>
''' <param name="definition">设置图片的清晰度,数字越大越清晰</param>
Public Sub ConvertPDF2Image(pdfInputPath As String, imageOutputPath As String, imageName As String, startPageNum As Integer, endPageNum As Integer, imageFormat As ImageFormat, _
definition As Definition)
Dim pdfFile__1 As O2S.Components.PDFRender4NET.PDFFile = O2S.Components.PDFRender4NET.PDFFile.Open(pdfInputPath)
If Not IO.Directory.Exists(imageOutputPath) Then
IO.Directory.CreateDirectory(imageOutputPath)
End If
' validate pageNum
If startPageNum <= 0 Then
startPageNum = 1
End If
If endPageNum > pdfFile__1.PageCount Then
endPageNum = pdfFile__1.PageCount
End If
If startPageNum > endPageNum Then
Dim tempPageNum As Integer = startPageNum
startPageNum = endPageNum
endPageNum = startPageNum
End If
' start to convert each page
For i As Integer = startPageNum To endPageNum
Dim pageImage As Bitmap = pdfFile__1.GetPageImage(i - 1, 56 * CInt(definition))
pageImage.Save(imageOutputPath & imageName & i.ToString() & "." & imageFormat.ToString(), imageFormat)
pageImage.Dispose()
Next
pdfFile__1.Dispose()
End Sub