In This Topic
Programming / Document Printing / How to print documents using GdPicturePDF

How to print documents using GdPicturePDF

In This Topic

GdPicturePDF is a class designed for all PDF related activities. So printing PDF documents can also be done using this class.

Here is an example how to load a PDF document to a GdPicturePDF instance and then print it.

Copy Code
'We assume that GdPicture has been correctly installed and unlocked.

'Initializing the GdPicturePDF object.

Using oGdPicturePDF As New GdPicturePDF()

    If oGdPicturePDF.LoadFromFile("document_to_print.pdf", False) = GdPictureStatus.OK Then

        'Enabling the pre-rasterization option.

        oGdPicturePDF.PrintSetPreRasterization(True);

        If oGdPicturePDF.Print() = GdPictureStatus.OK Then

            MessageBox.Show("The file has been printed successfully.", "Printing Example", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Else

            Dim message As String = "The file can't be printed." + vbCrLf + "Status: " + oGdPicturePDF.PrintGetStat().ToString()

            If oGdPicturePDF.PrintGetStat() = GdPictureStatus.PrintingException Then

                message = message + "    Error: " + oGdPicturePDF.PrintGetLastError()

            End If

            MessageBox.Show(message, "Printing Example", MessageBoxButtons.OK, MessageBoxIcon.Information)

        End If

        oGdPicturePDF.CloseDocument()

    Else

        MessageBox.Show("The file can't be loaded. Status: " + oGdPicturePDF.GetStat().ToString(), "Printing Example", MessageBoxButtons.OK, MessageBoxIcon.Error)

    End If

End Using
Copy Code
//We assume that GdPicture has been correctly installed and unlocked.

//Initializing the GdPicturePDF object.

using (GdPicturePDF pdf = new GdPicturePDF())

{

    if (pdf.LoadFromFile("document_to_print.pdf", false) == GdPictureStatus.OK)

    {

        //Enabling the pre-rasterization option.

        pdf.PrintSetPreRasterization(true);

        if (pdf.Print() == GdPictureStatus.OK)

        {

            MessageBox.Show("The file has been printed successfully.", "Printing Example", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }

        else

        {

            string message = "The file can't be printed.\nStatus: " + pdf.PrintGetStat().ToString();

            if (pdf.PrintGetStat() == GdPictureStatus.PrintingException)

                message = message + "    Error: " + pdf.PrintGetLastError();

            MessageBox.Show(message, "Printing Example", MessageBoxButtons.OK, MessageBoxIcon.Error);

        }

        pdf.CloseDocument();

    }

    else

    {

        MessageBox.Show("The file can't be loaded. Status: " + pdf.GetStat().ToString(), "Printing Example", MessageBoxButtons.OK, MessageBoxIcon.Error);

    }

}