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
225
Trying to print with UltraGridPrintDocument but chosen settings not applied
posted

I'm trying to print the contents of my UltraGrid with UltraGridPrintDocument. I bring up the Windows Print dialog to allow the user to select a printer. The problem seems to be that the PrinterSettings of the selected printer are not being used by the UltraGridPrintDocument. Instead, it's using the PrinterSettings of the default printer on the system. Code is attached below. I'm using Infragistics 15.2

if (_gridPrintDocument == null)
{

    _gridPrintDocument = new UltraGridPrintDocument();

    _gridPrintDocument.Grid = _gridInternal; // my UltraGrid

    _gridPrintDocument.Footer.BorderStyle = UIElementBorderStyle.Solid;

    _gridPrintDocument.Footer.Appearance.BackColor = Color.LightGray;
    _gridPrintDocument.Footer.Margins.Top = 5;
    _gridPrintDocument.Footer.Margins.Bottom = 5;

}

using (IPrintDialog printDialog = new WindowsPrintDialog())
{
    printDialog.Document = _gridPrintDocument;

    printDialog.ShowHelp = true;

    bool? result = printDialog.ShowDialog(ApplicationContext.Current.MainWindowHandle);

    if (result.GetValueOrDefault())
    {
        _gridPrintDocument.Print();
    }
}

I've debugged through the code and after the user chooses a printer, I verified that _gridPrintDocument.PrinterSettings is updated with the selected printer's settings, but when calling 'Print', these settings seem to be ignored and it's using the settings for the system's default printer. Specifically it's the Page Size property that's causing a problem for us. The user has a small format label printer as their default, and they select a "standard" printer (with 8.5x11 pages) in the Print dialog, and they are getting this error: "Printing failed. The Header area is taller than the page leaving no room to print any row data. Reduce the height of the headers and try again."

Also, when using the Infragistics Print Preview dialog, even though the paper size is set to 'Letter', it's sizing the grid data on the page based on the (small) default printer's paper size. I'll try to attach a screenshot.

Parents
No Data
Reply
  • 4625
    Offline posted

    Hi Chris,

    Thank you for posting in our forums!

    I understand what happens and it is something that I can’t find a reasonable explanation about. Let me clarify something. The UltraGridPrintDocument is derived from Microsoft’s PrintDocument class. The Print method can’t be overridden and as a result it is reused from our class. The PrintSettings property is also derived by the PrintDocument class. As a result, we are with tied hands in your scenario regarding fixing it, because it is Microsoft’s code.

    In order to investigate it further, I recommend you to handle BeginPrint and EndPrint events, where you can check out what settings are being applied then. It would be very strange if they are still the non-default printer’s one, but at the same time the Print method uses the default printer’s settings.

    What I found regarding your issue is the following forum thread , related to user specific settings.

    What’s the operating system this issue is reproducible on? Are all printer drivers installed correctly and are up to date?

Children
No Data