UI control for PDF printing

The GdViewer class has numerous print functions. They’re all automatically bounded to the currently displayed document in the GdViewer control, regardless of whether it’s a single image file or a multipage TIFF, PDF, GIF, or JBIG2.

The following code shows how to print using the GdViewer class and a print button:

// We assume 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),
// GdViewer prompts printing 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);
}
}