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

How to print displayed documents using GdViewer

In This Topic

The GdViewer class has numerous print functions. They are all automatically bounded to the current displayed document in the GdViewer control, whether a single image file or a multipage Tiff, PDF, GIF, or JBIG2. GdViewer printing is used in our Document Viewer Sample and Annotations Sample demos.

Here is a simple example how to achieve printing using the GdViewer class and a print button.

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

'We assume the GdViewer object called GdViewer1 has been created and painted on the form.

Dim oGdPictureImaging As New GdPictureImaging

'Loading the image from a file.

Dim imageId As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("C:\\Image.tif")

'Checking if the image resource has been loaded correctly.

If oGdPictureImaging.GetStat() <> GdPictureStatus.OK

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

Else

    'Displaying the image in the GdViewer.

    GdViewer1.DisplayFromGdPictureImage(imageId)

End If

oGdPictureImaging.Dispose()



'On the Print Button Click event (a button you created on your form):

'the GdViewer prompts to print the displayed document according to the current parameters.

Public Sub Print(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

   GdViewer1.PrintSetColorMode(PrinterColorMode.PrinterColorModeColor)

   GdViewer1.PrintSetDocumentName("GdPicture printing")

   GdViewer1.PrintSetShowPrintingProgress(False)

   GdViewer1.PrintSetPaperBin(1) 'upper bin

   GdViewer1.PrintSetQuality(PrintQuality.PrintQualityDraft)

   GdViewer1.PrintSetCopies(2)

   GdViewer1.PrintSetDuplexMode(Duplex.Horizontal)

   GdViewer1.PrintSetStdPaperSize(9) 'A4

   GdViewer1.PrintSetAutoRotation(True)

   GdViewer1.PrintSetFromToPage(1, 5)

   GdViewer1.Print()

   Dim status As GdPictureStatus = GdViewer1.PrintGetStat()

   If status = GdPictureStatus.OK Then

      MessageBox.Show("The document is printed.", "Printing Example", MessageBoxButtons.OK, MessageBoxIcon.Information)

   Else

      MessageBox.Show("The document is not printed. Error: " + GdViewer1.PrintGetLastError(), "Printing Example", MessageBoxButtons.OK, MessageBoxIcon.Error)

   End If

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

//We assume the GdViewer object called GdViewer1 has been created and painted on the form.

GdPictureImaging oGdPictureImaging = new GdPictureImaging();

//Loading the image from a file.

int imageId = oGdPictureImaging.CreateGdPictureImageFromFile("C:\\Image.tif");

//Checking if the image resource has been loaded correctly.

if (oGdPictureImaging.GetStat() != GdPictureStatus.OK)

{

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

}

else

{

    //Displaying the image in the GdViewer.

    GdViewer1.DisplayFromGdPictureImage(imageId);

}

oGdPictureImaging.Dispose();



//On the Print Button Click event (a button you created on your form):

//the GdViewer prompts to print the displayed document according to the current parameters.

public void Print_button1_click(System.Object sender, System.EventArgs e)

{

    GdViewer1.PrintSetColorMode(PrinterColorMode.PrinterColorModeColor);

    GdViewer1.PrintSetDocumentName("GdPicture printing");

    GdViewer1.PrintSetShowPrintingProgress(false);

    GdViewer1.PrintSetPaperBin(1); //upper bin

    GdViewer1.PrintSetQuality(PrintQuality.PrintQualityDraft);

    GdViewer1.PrintSetCopies(2);

    GdViewer1.PrintSetDuplexMode(System.Drawing.Printing.Duplex.Horizontal);

    GdViewer1.PrintSetStdPaperSize(9); //A4

    GdViewer1.PrintSetAutoRotation(true);

    GdViewer1.PrintSetFromToPage(1, 5);

    GdViewer1.Print();

    GdPictureStatus status = GdViewer1.PrintGetStat();

    if (status == GdPictureStatus.OK)

    {

        MessageBox.Show("The document is printed.", "Printing Example", MessageBoxButtons.OK, MessageBoxIcon.Information);

    }

    else

    {

        MessageBox.Show("The document is not printed. Error: " + GdViewer1.PrintGetLastError(), "Printing Example", MessageBoxButtons.OK, MessageBoxIcon.Error);

    }

}