C# 打印机仅在页面的大约 1/6 处打印报告
C# printer does print report in only about 1/6 of the page
自从我将 ActiveReports 从 7 版升级到 11 版后,报告打印在页面的大约 1/6 处并且布局奇怪,只有图片被正确打印。
但显然它只是在打印时,而不是预览时。看起来很奇怪,我希望问题出在 SystemPrinter
对象上。
就我的理解而言,此对象已正确定义。
// 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 Whosebug: 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();
}
与PaperHeight being 11.69f
和PaperWidth being 8.27f
、ClipBounds being {X = -699050.6 Y = -699050.6 Width = 1398101.25 Height = 1398101.25} System.Drawing.RectangleF
然而,我不能过分强调我只将 ActiveReports 版本更改为 11(现在使用 inches
进行测量,但预览仍然正常。当我在物理上打印时输出不会改变打印机或 bullzip 打印机。
有人对此有一些见解吗?
编辑:
在使用已经编写的方法打印报告之前,pdf 看起来很完美。
var pdfReportArchiv = new PdfExport();
pdfReportArchiv.Security.Encrypt = encrypt;
pdfReportArchiv.Security.Permissions = PdfPermissions.AllowPrint;
pdfReportArchiv.Security.Use128Bit = true;
pdfReportArchiv.Export(report.Document, pathAndName);
显然,随着从 7 到 11 的更改,行 systemPrinter.Graphics.PageUnit = GraphicsUnit.Pixel;
不再使用并导致了问题。
自从我将 ActiveReports 从 7 版升级到 11 版后,报告打印在页面的大约 1/6 处并且布局奇怪,只有图片被正确打印。
但显然它只是在打印时,而不是预览时。看起来很奇怪,我希望问题出在 SystemPrinter
对象上。
就我的理解而言,此对象已正确定义。
// 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 Whosebug: 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();
}
与PaperHeight being 11.69f
和PaperWidth being 8.27f
、ClipBounds being {X = -699050.6 Y = -699050.6 Width = 1398101.25 Height = 1398101.25} System.Drawing.RectangleF
然而,我不能过分强调我只将 ActiveReports 版本更改为 11(现在使用 inches
进行测量,但预览仍然正常。当我在物理上打印时输出不会改变打印机或 bullzip 打印机。
有人对此有一些见解吗?
编辑:
在使用已经编写的方法打印报告之前,pdf 看起来很完美。
var pdfReportArchiv = new PdfExport();
pdfReportArchiv.Security.Encrypt = encrypt;
pdfReportArchiv.Security.Permissions = PdfPermissions.AllowPrint;
pdfReportArchiv.Security.Use128Bit = true;
pdfReportArchiv.Export(report.Document, pathAndName);
显然,随着从 7 到 11 的更改,行 systemPrinter.Graphics.PageUnit = GraphicsUnit.Pixel;
不再使用并导致了问题。