Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
175
Using the Infragistics.Documents code library with an UltraPrintPreviewDialog
posted

In my current application I'm using an UltraPrintPreviewDialog to display the results of the .NET generated output to the user so they can check values before printing.  They needed to be able to email a PDF of the same information, so I recreated their current output using the Infragistics.Documents code library.

So, now I have better code that can be printed or sent as a PDF... however, I can't figure out how to get the code to work with the print preview dialog...

Is this possible?

Thanks,

Scot

Parents
  • 1158
    Verified Answer
    Offline posted

    Hi Scot, happy new year ;)

    Yes it's possible ;)

    I have had the same problem, and I solved with the code at bottom of message, you can put it in a class or where you want.

    I wrote this code gettings ideas and parts of code from Infragistics Samples, Forum and Sources, if I well remember.

    The idea is:
    when UPreviewDialog print an "virtual" UPrintDocument, I draw the the IProjectionPage, coming from pages  filled by Report.Generate(), on the graph surface of the page of the "virtual" UPrintDocument.
    That it's all and work fine, after some test & refine.

    The source code is not beautiful but it's work, if you have any troubles, write a post ;)

    Have a fabulous 2008

    Davide Dolla
    neoDD69

    using Infragistics.Win.Printing;
    using Infragistics.Documents;
    using Infragistics.Documents.Report;
    using Infragistics.Documents.Report.Projection;

    UltraPrintPreviewDialog uPrvDlg = new UltraPrintPreviewDialog();
    IProjectionPageCollection pages;
    UltraPrintPreviewDialog uPrvDlg = new UltraPrintPreviewDialog();
    int currentPrintPageNumber;
    public void Preview(Report Report)
    {
    Infragistics.Win.Printing.
    UltraPrintDocument ultraPrintDocument1 = new UltraPrintDocument();
    ultraPrintDocument1.PrintPage +=
    new System.Drawing.Printing.PrintPageEventHandler(ultraPrintDocument1_PrintPage);
    this.uPrvDlg.Document = ultraPrintDocument1;
    this.uPrvDlg.Printing += new PrintingEventHandler(uPrvDlg_Printing);
    this.pages = Report.Generate();
    this.currentPrintPageNumber = 0;
    // Show the dialog.
    this.uPrvDlg.FindForm().WindowState = System.Windows.Forms.FormWindowState.Maximized;
    this.uPrvDlg.Style = Infragistics.Win.UltraWinToolbars.ToolbarStyle.Office2007;
    this.uPrvDlg.ShowDialog();
    ultraPrintDocument1.PrintPage -=
    new System.Drawing.Printing.PrintPageEventHandler(ultraPrintDocument1_PrintPage);
    this.uPrvDlg.Printing -= new PrintingEventHandler(uPrvDlg_Printing);
    ultraPrintDocument1.Dispose();
    ultraPrintDocument1 =
    null;
    }

    void uPrvDlg_Printing(object sender, PrintingEventArgs e)
    {
     currentPrintPageNumber = 0;
     e.Cancel =
    true;
     this.Report.Print(main.Sex.CurrentPrinter);
    }

    private void ultraPrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
    // Create a new Document Graphics object based on the printer page graphics.
    Infragistics.Documents.Graphics.Graphics reportGraphics = new Infragistics.Documents.Graphics.Graphics(e.Graphics);
    // Save the state of the Graphics object So we can restore it later.
    reportGraphics.SaveState();
    // Get the page margins in points.
    float leftMarginInPoints = (e.MarginBounds.Left / 100f) * 72f;
    float topMarginInPoints = (e.MarginBounds.Top / 100f) * 72f;
    // Get the available print width and height in points. This is the size
    // of the printable area of the page inside the margins.
    float availablePrintWidth = (e.MarginBounds.Width / 100f) * 72f;
    float availablePrintHeight = (e.MarginBounds.Height / 100f) * 72f;
    // Use a translate to shift the report page drawing inside the printer page margins.
    // Get the currently printing report page.
    IProjectionPage reportPage = pages[this.currentPrintPageNumber];
    // Scale the report page so that it fits inside the available print area.
    float widthRatio = availablePrintWidth / reportPage.Width;
    float heightRatio = availablePrintHeight / reportPage.Height;
    // Draw the page.
    reportPage.Draw(reportGraphics);
    // Restore the Graphics settings.
    reportGraphics.RestoreState();
    // Increment the page number.
    currentPrintPageNumber++;
    // If this is the last page, set HasMorePages to false.
    e.HasMorePages = currentPrintPageNumber < (pages.Count);
    }

     

Reply Children
No Data