Posted 2 February 2023, 8:27 am EST - Updated 2 February 2023, 9:42 am EST
I have a system where we print directly to the printer from the code base on the server.
In AR6 after a lot of effort I found that the following set of code was the best way to get printing to work properly:
var systemPrinter = new SystemPrinter();
systemPrinter.PrinterName = printer.Queue;
systemPrinter.PrinterSettings.Duplex = Duplex.Vertical;
systemPrinter.PaperSize = systemPrinter.PaperSizes[0];
if (activeReportToPrint.Document.Pages[0].Orientation == PageOrientation.Landscape)
{
systemPrinter.PrinterSettings.DefaultPageSettings.Landscape = true;
}
float pageWidth = activeReportToPrint.Document.Pages[0].Width;
float pageHeight = activeReportToPrint.Document.Pages[0].Height;
systemPrinter.StartJob(activeReportToPrint.Document.Name);
systemPrinter.Graphics.PageUnit = GraphicsUnit.Pixel;
float offsetX = (float)systemPrinter.PhysicalOffsetX / systemPrinter.Graphics.DpiX;
float offsetY = (float)systemPrinter.PhysicalOffsetY / systemPrinter.Graphics.DpiY;
RectangleF rectangleOfThePage = RectangleF.FromLTRB(0F - offsetX, 0F - offsetY, pageWidth - offsetX, pageHeight - offsetY);
for (int pageCounter = 0; pageCounter < activeReportToPrint.Document.Pages.Count; pageCounter++)
{
Page currentPageToPrint = activeReportToPrint.Document.Pages[pageCounter];
systemPrinter.StartPage();
currentPageToPrint.Draw(systemPrinter.Graphics, rectangleOfThePage);
systemPrinter.EndPage();
}
systemPrinter.EndJob();
This code now prints in a corner of the page, so I’ve tried simplifying it as per what looks like the latest instructions:
activeReportToPrint.Document.Printer.Landscape = (activeReportToPrint.Document.Pages[0].Orientation == PageOrientation.Landscape);
activeReportToPrint.Document.Printer.PrinterSettings.PrinterName = printer.Queue;
activeReportToPrint.Document.Printer.PrinterSettings.Duplex = Duplex.Vertical;
activeReportToPrint.Document.Printer.Print();
My simplified code, prints a blank page instead of the report it is supposed to. So basically I’m trying to figure out what I need to do to get my code migrated and work accurately. Needs to set the queue at run time.
edit: A couple of things to note, this is a very large combined report made up of a variety of other reports. So I can’t print from directly within the report as suggested in many places, this is done via batch, so the viewer is also not possible to print from.