Foxtable(狐表)用户栏目专家坐堂 → [求助]利用pdfbox-Pdf转图片


  共有1735人关注过本帖树形打印复制链接

主题:[求助]利用pdfbox-Pdf转图片

帅哥哟,离线,有人找我吗?
天一生水
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1137 积分:11224 威望:0 精华:0 注册:2017/9/26 16:30:00
[求助]利用pdfbox-Pdf转图片  发帖心情 Post By:2019/11/7 21:38:00 [只看该作者]

老师好!
网上有一段pdfbox-Pdf转图片的代码:https://www.cnblogs.com/moonlignt/p/9233763.html
我把它转换成.net的代码后,把pdf2Image函数放入全局代码,怎样调用?
请老师指教。谢谢!


Public Sub pdf2Image(ByVal sourceFile As File, ByVal destFile As File)
    If sourceFile.exists() Then

        Try
            Dim doc As PDDocument = PDDocument.load(sourceFile)
            Dim renderer As PDFRenderer = New PDFRenderer(doc)
            Dim pageCount As Integer = doc.getNumberOfPages()
            Dim imageNew As BufferedImage = Nothing

            For i As Integer = 0 To pageCount - 1
                Dim image As BufferedImage = renderer.renderImageWithDPI(i, 284)
                Dim width As Integer = image.getWidth()
                Dim height As Integer = image.getHeight()

                If imageNew Is Nothing Then
                    imageNew = New BufferedImage(width, (height + SEPARATE_DISTANCE) * pageCount, BufferedImage.TYPE_INT_RGB)
                End If

                Dim imageRgbArray As Integer() = New Integer(width * height - 1) {}
                imageRgbArray = image.getRGB(0, 0, width, height, imageRgbArray, 0, width)
                imageNew.setRGB(0, (height + SEPARATE_DISTANCE) * i, width, height, imageRgbArray, 0, width)
            Next

            ImageIO.write(imageNew, "PNG", destFile)
        Catch e As IOException
            e.printStackTrace()
        End Try
    End If
End Sub

 回到顶部
帅哥哟,离线,有人找我吗?
天一生水
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1137 积分:11224 威望:0 精华:0 注册:2017/9/26 16:30:00
  发帖心情 Post By:2019/11/8 16:54:00 [只看该作者]

蓝老师好!

PDF转图片老师已经给过一个很好的示例了,再次表示感谢!

现在求助于老师,是因为这个PDFbox这个方法有个最大的好处是开源,不会涉及版权问题。

因此,希望如果老师有空的话,能再给学生指教一下。

谢谢!


 回到顶部