ComponentOne Reports for WinForms Designer Edition: ComponentOne Reports for WinForms > Working with C1PrintDocument > C1Report Definitions > Working with Printer Drivers

Working with Printer Drivers

Several new members in ComponentOne Reports for WinForms were added to work around specific problems caused by printer drivers.

The following members were added to resolve issues with printer drivers:

 

Class

Member

Description

C1PreviewPane

AdjustPrintPage event

Fired from within the PrintPage event handler of the C1PrintManager used to print the document.

C1PrintManager

AdjustPrintPage event

Fired from within the PrintDocument.PrintPage event handler of current print manager, prior to actually printing the page.

C1PrintOptions

DrawPrintableAreaBounds property

Gets or sets a value indicating whether a line is drawn around the printable area of the page (useful to debug printer issues).

PrintableAreaBoundsPen property

Gets or sets the pen used to draw printable area bounds if DrawPrintableAreaBounds is True.

PrintAsBitmap property

Gets or sets a value indicating whether page metafiles should be converted to bitmaps and clipped to printer's hard margins prior to printing.

 

The members listed in the table above may be used to work around certain printer issues. For instance, consider the following scenario of a machine running Windows Vista 64 with an HP-CP1700 printer (using Vista's built-in printer driver). In this example, if ClipPage was False (default) and a document page was wider than the printer's hard margin, empty pages were emitted and document content was not printed. For example, the following document produced just two empty pages if printed:

      Visual Basic

Dim doc As New C1PrintDocument()

doc.Style.Font = New Font("Arial", 32)

For i As Integer = 0 To 19

    Dim rtx As New RenderText(i.ToString())

    rtx.X = String.Format("{0}in", i)

    rtx.Y = "10cm"

    rtx.Style.FontSize = 64

    doc.Body.Children.Add(rtx)

Next

doc.Generate()

      C#

C1PrintDocument doc = new C1PrintDocument();

doc.Style.Font = new Font("Arial", 32);

for (int i = 0; i < 20; ++i)

{

    RenderText rtx = new RenderText(i.ToString());

    rtx.X = string.Format("{0}in", i);

    rtx.Y = "10cm";

    rtx.Style.FontSize = 64;

    doc.Body.Children.Add(rtx);

}

doc.Generate();

This issue can be now worked around by doing two things:

1.   Set PrintAsBitmap to True (for example, on C1PreviewPane).

2.   Attach the following event handler to the AdjustPrintPage event (available also via AdjustPrintPage):

      Visual Basic

Dim doc As New C1PrintDocument()

doc.Style.Font = New Font("Arial", 32)

Private  Sub PreviewPane_AdjustPrintPage(ByVal sender As Object, ByVal e As AdjustPrintPageEventArgs)

    Dim pa As RectangleF =  e.PrintableArea

    If Not e.PrintPageEventArgs.PageSettings.Landscape Then

        pa.Width = 800 ' System set to 824

        pa.X = 25 ' System set to 13

        pa.Y = 13 ' System set to 6.666...

    Else

        pa.X = 13

        pa.Y = 0

    End If

    e.PrintableArea = pa

End Sub

      C#

C1PrintDocument doc = new C1PrintDocument();

doc.Style.Font = new Font("Arial", 32);

void PreviewPane_AdjustPrintPage(object sender, AdjustPrintPageEventArgs e)

{

    RectangleF pa = e.PrintableArea;

    if (!e.PrintPageEventArgs.PageSettings.Landscape)

    {

        pa.Width = 800; // System set to 824

        pa.X = 25; // System set to 13

        pa.Y = 13; // System set to 6.666...

    }

    else {

        pa.X = 13;

        pa.Y = 0;

    }

    e.PrintableArea = pa;

}

This code fixes the wrong hard page margins set by the printer driver, and avoids the problem described above.


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.