ImageGear .NET
Print Method (ImGearPageDisplay)
Example 




Graphics object to draw the image on.
Draws the image on .NET Graphics for printing. Call to Print(hdc) is equal to call DrawEx(null, hdc, true).
Syntax
'Declaration
 
Public Sub Print( _
   ByVal graphics As Graphics _
) 
'Usage
 
Dim instance As ImGearPageDisplay
Dim graphics As Graphics
 
instance.Print(graphics)
public void Print( 
   Graphics graphics
)
public: void Print( 
   Graphics* graphics
) 
public:
void Print( 
   Graphics^ graphics
) 

Parameters

graphics
Graphics object to draw the image on.
Example
private void PrintPage(object sender, EventArgs e)
{
    // Load an image
    ImGearPage igPage;
    using (FileStream localFile = new FileStream("test1.tif", FileMode.Open))
    {
        igPage = ImGearFileFormats.LoadPage(localFile, 0);
    }
    // Create a new ImGearPageDisplay based upon an ImGearPage.
    ImGearPageDisplay igPageDisplay = new ImGearPageDisplay(igPage);
    // Set the current ImGearPageView to use this new display.
    imGearPageView.Display = igPageDisplay;
    // Initialize a PrintDialog for the user to select a printer.
    using (PrintDocument document = new PrintDocument())
    using (PrintDialog printDialog = new PrintDialog())
    {
        printDialog.Document = document;
        // Set the page range to 1 page.
        printDialog.AllowSomePages = true;
        printDialog.PrinterSettings.MinimumPage = 1;
        printDialog.PrinterSettings.MaximumPage = 1;
        printDialog.PrinterSettings.FromPage = 1;
        printDialog.PrinterSettings.ToPage = 1;
        
        if (DialogResult.OK == printDialog.ShowDialog(this))
        {
            // Set a name for the print job.
            document.DocumentName = this.Text;
            // Define a PrintPage event handler and start printing.
            document.PrintPage +=
                new PrintPageEventHandler(HandlePrinting);
            document.Print();
        }
    }
}

void HandlePrinting(object sender, PrintPageEventArgs args)
{
    // Clone the current Display for use as a printing display.
    ImGearPageDisplay igPageDisplayPrinting =
        imGearPageView.Display.Clone();
    igPageDisplayPrinting.Page = imGearPageView.Display.Page;
    // Get the current Zoom settings and disabled fixed zoom.
    ImGearZoomInfo igZoomInfo =
        igPageDisplayPrinting.GetZoomInfo(imGearPageView);
    igZoomInfo.Horizontal.Fixed =
        igZoomInfo.Vertical.Fixed = false;
    igPageDisplayPrinting.UpdateZoomFrom(igZoomInfo);
    // Disable any background before printing.
    igPageDisplayPrinting.Background.Mode =
        ImGearBackgroundModes.NONE;
    // Print to the Graphics device chosen from the PrintDialog.
    igPageDisplayPrinting.Print(args.Graphics);
    // Let the PrintDialog know there are no more pages.
    args.HasMorePages = false;
}
Private Sub PrintPage(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                Handles ImGearPageDisplayPrintToolStripMenuItem.Click
    'Load an image
    Dim igPage As ImGearPage
    Dim localFile As FileStream = New FileStream("test1.tif", FileMode.Open)
    Try
        igPage = ImGearFileFormats.LoadPage(localFile, 0)
    Finally
        localFile.Close()
    End Try
    'Create a new ImGearPageDisplay based upon an ImGearPage.
    Dim igPageDisplay As ImGearPageDisplay = New ImGearPageDisplay(igPage)
    'Set the current ImGearPageView to use this new display.
    ImGearPageView1.Display = igPageDisplay
    'Initialize a PrintDialog for the user to select a printer.

    Dim document As PrintDocument = New PrintDocument()
    Dim printDialog As PrintDialog = New PrintDialog()
    Try
        printDialog.Document = document
        'Set the page range to 1 page.
        printDialog.AllowSomePages = True
        printDialog.PrinterSettings.MinimumPage = 1
        printDialog.PrinterSettings.MaximumPage = 1
        printDialog.PrinterSettings.FromPage = 1
        printDialog.PrinterSettings.ToPage = 1

        If (printDialog.ShowDialog(Me) = DialogResult.OK) Then
            'Set a name for the print job.
            document.DocumentName = Me.Text
            'Define a PrintPage event handler and start printing.
            AddHandler document.PrintPage, _
                New PrintPageEventHandler(AddressOf HandlePrinting)
            document.Print()
        End If
    Finally
        printDialog.Dispose()
        document.Dispose()
    End Try
End Sub

Private Sub HandlePrinting(ByVal sender As Object, ByVal args As PrintPageEventArgs)
    'Clone the current Display for use as a printing display.
    Dim igPageDisplayPrinting As ImGearPageDisplay = _
        ImGearPageView1.Display.Clone()
    igPageDisplayPrinting.Page = ImGearPageView1.Display.Page
    'Get the current Zoom settings and disabled fixed zoom.
    Dim igZoomInfo As ImGearZoomInfo = _
        igPageDisplayPrinting.GetZoomInfo(ImGearPageView1)
    igZoomInfo.Horizontal.Fixed = False
    igZoomInfo.Vertical.Fixed = False
    igPageDisplayPrinting.UpdateZoomFrom(igZoomInfo)
    'Disable any background before printing.
    igPageDisplayPrinting.Background.Mode = _
        ImGearBackgroundModes.NONE
    'Print to the Graphics device chosen from the PrintDialog.
    igPageDisplayPrinting.Print(args.Graphics)
    'Let the PrintDialog know there are no more pages.
    args.HasMorePages = False
End Sub
See Also

Reference

ImGearPageDisplay Class
ImGearPageDisplay Members

 

 


©2016. Accusoft Corporation. All Rights Reserved.

Send Feedback