.NET PDF转图片

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,可以联系我~

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值