老师好!网上有一段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