Imports System.IO
Imports Foxit.PDF.Rasterizer

Namespace RgbaImage_Example
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            Dim pdfPath As String = GetPDFPath()

            'Create a PdfRasterizer
            Dim rasterizer As New PdfRasterizer(Path.Combine(pdfPath, "DocumentA.pdf"))

            ' Create a FixedImageSize object with required width and height.
            Dim fixedImageSize As New FixedImageSize(595, 841)

            'Create a PngImageFormat object with rgba color.
            Dim oPngImageFormat As New PngImageFormat(PngColorFormat.RgbA)

            ' Save the image.
            rasterizer.Draw("RgbaImage.png", oPngImageFormat, fixedImageSize)
        End Sub
        Private Shared Function GetPDFPath() As String
            Dim pdfPath As String = AppDomain.CurrentDomain.BaseDirectory
            If pdfPath.EndsWith(New String(Path.DirectorySeparatorChar, 1)) Then
                pdfPath = Path.GetDirectoryName(pdfPath)
            End If
            Do While Directory.Exists(pdfPath) AndAlso Not Directory.Exists(Path.Combine(pdfPath, "PDFs"))
                pdfPath = Path.GetDirectoryName(pdfPath)
            Loop
            If pdfPath Is Nothing OrElse (Not Directory.Exists(Path.Combine(pdfPath, "PDFs"))) Then
                Throw New Exception("File path for pdf files could not be found.")
            End If

            Return pdfPath & "\PDFs"
        End Function
    End Class
End Namespace
