以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]利用pdfbox-Pdf转图片  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=142875)

--  作者:天一生水
--  发布时间:2019/11/7 21:38:00
--  [求助]利用pdfbox-Pdf转图片
老师好!
网上有一段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

--  作者:天一生水
--  发布时间:2019/11/8 16:54:00
--  

蓝老师好!

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

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

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

谢谢!