Imports System.IO
Imports Foxit.PDF.Rasterizer

Namespace IndexedImage_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 the GifImageFormat object.
            Dim gifImageFormat As New GifImageFormat()

            ' Set the DitheringAlgorithm to FloydSteinberg.
            gifImageFormat.DitheringAlgorithm = DitheringAlgorithm.FloydSteinberg

            ' Set the DitheringPercent.
            gifImageFormat.DitheringPercent = 100

            ' Set the size.
            Dim fixedImageSize As New FixedImageSize(595, 841)

            ' Save the image.
            rasterizer.Draw("IndexedImage.Gif", gifImageFormat, 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
