Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

Using the Infragistics.Documents code library with an UltraPrintPreviewDialog

Last post 07-17-2008 14:39 by abbarnes1. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 01-03-2008 11:18

    • Scot Simon
    • Not Ranked
    • Joined on 01-03-2008
    • Rome, GA
    • Points 40

    Using the Infragistics.Documents code library with an UltraPrintPreviewDialog

    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

    • Post Points: 20
  • 01-03-2008 13:41 In reply to

    • Davide Dolla
    • Not Ranked
    • Joined on 11-26-2007
    • Imperia - Italy
    • Points 90

    Re: Using the Infragistics.Documents code library with an UltraPrintPreviewDialog

    Answer

    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);
    }

     

    Davide Dolla
    neoDD69
    • Post Points: 35
  • 01-04-2008 10:38 In reply to

    • Scot Simon
    • Not Ranked
    • Joined on 01-03-2008
    • Rome, GA
    • Points 40

    Re: Using the Infragistics.Documents code library with an UltraPrintPreviewDialog

    Davide,

    Happy New Year to you as well!

    Although I made a good effort, I can't pretend to understand all the inner-workings of your code; however, it worked beautifully!  I'll figure out how it works at a later time!

    Thanks for sharing your insight!

    Scot

    • Post Points: 20
  • 01-05-2008 6:54 In reply to

    • Davide Dolla
    • Not Ranked
    • Joined on 11-26-2007
    • Imperia - Italy
    • Points 90

    Re: Using the Infragistics.Documents code library with an UltraPrintPreviewDialog

    Scot,

    I'm happy that it works into you code Cool

    I'm using this code in my framework to give to the user the ability to preview the document generated with the outstanding UltraDocument class, and I don't have any problems.... but the documents are bills, 1/3 pages long. Probably with bigger document you will can see more problems (performance, memory...).

    IMO there are not other ways to preview directly the Report generated from UDocument class, it save only.
    Clearly always that Infra not release a new and improved UltraDocument... may be with a visual editor (in an post in the old forums, Infragistics's people says that an editor/previewer are not in they R&D plans [:'(] ).

    You welcome Smile

    Davide Dolla

    Davide Dolla
    neoDD69
    • Post Points: 5
  • 07-17-2008 14:39 In reply to

    Re: Using the Infragistics.Documents code library with an UltraPrintPreviewDialog

     David,

     

    Absolutely beautiful work.  When I started using it I did notice that some of my reports were cut off and I could not figure out why.  Just for the reference of other folks that may use this code - add in reportGraphics.Scale(widthRatio, heightRatio) before you draw the page. 

     

    Thanks,

     

    Andrew Barnes

    • Post Points: 5
Page 1 of 1 (5 items)
Powered by Community Server (Commercial Edition), by Telligent Systems