Search code examples
c#printingconfigurationactivereportspage-layout

C# printer does print report in only about 1/6 of the page


Ever since I upgraded ActiveReports from version 7 to 11 the reports get printed at about 1/6 of the page and with weird layouting, only the pictures being printed correctly.enter image description here
But apparently it only is when printing, not previewing it. As strange as it seems, I expect the problem to be the SystemPrinter object.
As far as my understanding goes this object is properly defined.

// get printer
if (systemPrinter == null)
{
    systemPrinter = new SystemPrinter { PrinterName = systemPrinterName };
    systemPrinter.StartJob("My-printjob");
}

// set paper source and size
SetPaper(systemPrinter, systemPrinterPaperSource);

// set draw size
var internalOffSetX = systemPrinter.PhysicalOffsetX / systemPrinter.Graphics.DpiX;
var internalOffSetY = systemPrinter.PhysicalOffsetY / systemPrinter.Graphics.DpiY;

internalOffSetX = internalOffSetX - (offSetX / 2.54f);
internalOffSetY = internalOffSetY - (offSetY / 2.54f);

var printWidth = (systemPrinter.PaperSize.Width / 100f) - internalOffSetX;
var printHight = (systemPrinter.PaperSize.Height / 100f) - internalOffSetY;

// Scale: A4 (printable)
var smlOut = RectangleF.FromLTRB(-internalOffSetX, -internalOffSetY, printWidth, printHight);

systemPrinter.Graphics.PageUnit = GraphicsUnit.Pixel;

//Important edit for StackOverflow: Just added this line and the pdf looks perfect
SaveDocumentAsPdf(@"C:\Temp\SaveAsPDF\mydocument.pdf", report);

foreach (Page page in report.Document.Pages)
{
    systemPrinter.StartPage();
    page.Draw(systemPrinter.Graphics, smlOut);
    systemPrinter.EndPage();
}

With the PaperHeight being 11.69f and the PaperWidth being 8.27f, ClipBounds being {X = -699050.6 Y = -699050.6 Width = 1398101.25 Height = 1398101.25} System.Drawing.RectangleF

However I can't stress enough on the fact that I only changed the ActiveReports version to 11 (which now uses inches for messurement, but the preview still being ok. Output doesn't change when I print it on a phyiscal printer or a bullzip printer.
Does anyone have some insight on this?

Edit:
Just before printing the report by using a method that has already been written, the pdf looks perfect.

var pdfReportArchiv = new PdfExport();
pdfReportArchiv.Security.Encrypt = encrypt;
pdfReportArchiv.Security.Permissions = PdfPermissions.AllowPrint;
pdfReportArchiv.Security.Use128Bit = true;
pdfReportArchiv.Export(report.Document, pathAndName);

Solution

  • Apparantly with the change from 7 to 11 the line systemPrinter.Graphics.PageUnit = GraphicsUnit.Pixel;was no longer used and caused the problem.