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
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 DollaneoDD69
using Infragistics.Win.Printing;using Infragistics.Documents;using Infragistics.Documents.Report;using Infragistics.Documents.Report.Projection;
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, thanks for this, helped tons!
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.
Andrew Barnes
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!