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
405
Hooking in to WinPrintPreviewDialog/PrintDocument to rebuild report after PageSettings modification
posted

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)

private void preview(Report Report)

{

ultraPrintDocument1 =
new UltraPrintDocument();

ultraPrintDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(ultraPrintDocument1_PrintPage);

this.uPrvDlg.Document = ultraPrintDocument1;

this.uPrvDlg.Printing += new PrintingEventHandler(uPrvDlg_Printing);

this.uPrvDlg.Document.DefaultPageSettings = Globals.PgSettings;

this.uPrvDlg.Document.PrinterSettings = Globals.PrtSettings;

this.uPrvDlg.PageSetupDialogDisplaying += new PageSetupDialogDisplayingEventHandler(uPrvDlg_PageSetupDialogDisplaying);

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_PageSetupDialogDisplaying(object sender, PageSetupDialogDisplayingEventArgs e)

{

//reset the page number counter so the generated preview starts at the beginning again.

this.currentPrintPageNumber = 0;

}

private void uPrvDlg_Printing(object sender, PrintingEventArgs e)

{

currentPrintPageNumber = 0;

e.Cancel =
true;

//bring up the printer settings dialog box

openPrintDialog();

}

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;

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

}

Parents
No Data
Reply
  • 54937
    Verified Answer
    Offline posted

    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. 

Children