VB.NET PDF转图片
该方法引用了第三方的dll
首先需要添加引用O2S.Components.PDFRender4NET.dll
Imports O2S.Components.PDFRender4NET
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
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 definition As Definition) '用O2S.Components.PDFRender4NET来完成PDF转图片 Dim PDFFile As PDFFile = PDFFile.Open(pdfInputPath) If (Directory.Exists(imageOutputPath)) = False Then Directory.CreateDirectory(imageOutputPath) End If 'validate pageNum If (startPageNum <= 0) Then startPageNum = 1 End If If (endPageNum > PDFFile.PageCount) Then endPageNum = PDFFile.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 = startPageNum To endPageNum Dim pageImage As Bitmap = PDFFile.GetPageImage(i - 1, 56 * Int(definition)) pageImage.Save(imageOutputPath + imageName + i.ToString() + "." + imageFormat.ToString(), imageFormat) pageImage.Dispose() Next PDFFile.Dispose() End Sub
①pdfInputPath:PDF文件路径
②imageOutputPath:图片输出路径
③imageName:生成图片的名字
④startPageNum:从PDF文档的第几页开始转换
⑤endPageNum:从PDF文档的第几页开始停止转换
⑥imageFormat:设置所需图片格式
⑦definition:设置图片的清晰度,数字越大越清晰
也可以去掉这个参数,在函数中直接设置所需的dpi
Dim pageImage As Bitmap = PDFFile.GetPageImage(i - 1, 200)
如果需要O2S.Components.PDFRender4NET.dll,可以联系我~