I am using the IG Document Engine to generate a report that contains grids whose column widths and fonts are scaled based on the target page size, orientation and margins. (This is working.)
I have also wired up a IG PrintPreviewDialog to support Print Preview functionality based on code found elsewhere in the IG forum. (see code below.)
The challenge I can't seem to overcome is that I have found no way (exposed event) that will allow me to force my report to rebuild after the user changes page settings in the PrintPreviewDialog. I've got access to the PageSetupDialogDisplaying event, but that obviously fires before the changes are made.
Anyone know where I can hook in to rebuild my underlying report so user page setting changes can be reflected in the print preview dialog? (BTW: Currently the previews page does respond to the changes, but the grids printed to the updated page do not change to reflect the new page dimensions.)
Here's my print preview code (mostly pulled from a prior IG forum post)
{
ultraPrintDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(ultraPrintDocument1_PrintPage);
this.uPrvDlg.Printing += new PrintingEventHandler(uPrvDlg_Printing);
this.uPrvDlg.Document.PrinterSettings = Globals.PrtSettings;
this.pages = Report.Generate();
// Show the dialog.
//this.uPrvDlg.FindForm().WindowState = System.Windows.Forms.FormWindowState.Maximized;
//this.uPrvDlg.Style = Infragistics.Win.UltraWinToolbars.ToolbarStyle.Office2007;
ultraPrintDocument1.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(ultraPrintDocument1_PrintPage);
ultraPrintDocument1.Dispose();
}
//reset the page number counter so the generated preview starts at the beginning again.
currentPrintPageNumber = 0;
//bring up the printer settings dialog box
openPrintDialog();
// Create a new Document Graphics object based on the printer page graphics.
// Save the state of the Graphics object So we can restore it later.
reportGraphics.SaveState();
// Get the page margins in points.
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 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.
// Scale the report page so that it fits inside the available print area.
float heightRatio = availablePrintHeight / reportPage.Height;
//reportGraphics.Scale(widthRatio, heightRatio);
// 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);
Currently there is no event raised after the component shows the page setup dialog and no indication as to whether anything changed. You can submit a suggestion for adding this in a future version. For now, you would probably need to cancel the printpreviewdialog from showing the page setup, show one yourself and then after its closed check to see if the the user changed any of the settings of the page setup dialog's PageSettings and if so, update your report settings as well as call InvalidatePreview on the UltraPrintPreviewDialog.
I think your approach will work great. Thank you for providing a work-around!
At your service,
Jeff