Differences in printing between AR 6 vs. 12

Posted by: chris.horn on 2 February 2023, 8:27 am EST

    • Post Options:
    • Link

    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.

  • Posted 2 February 2023, 10:12 pm EST

    Hi Chris,

    I would suggest you to try using the SectionDocument.Print extension method to print the document also make sure to include the GrapeCity.ActiveReports.Viewer.Win.v12 DLL to consume the Print Extension class. Please refer to the following lines of code:

    activeReportToPrint.Document.Print(false,false,true);
    

    Please note ActiveReports 12 is a legacy product and we no longer support it. I would suggest you to upgrade to the latest version of ActiveReports i.e. ActiveReports 17 to consume latest features and bug fixes.

    You may download ActiveReports 17 with a 30-Day Trial using the following link: Download ActiveReports.

    Regards,

    Akshay

  • Posted 8 February 2023, 1:56 am EST

    Thank you, that worked. It seemed to need a couple of extra lines, so here is the complete code for anyone else that comes across a similar issue.

                    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.PrinterSettings.FromPage = 1;
                    activeReportToPrint.Document.Printer.PrinterSettings.ToPage = activeReportToPrint.Document.Pages.Count;
                    activeReportToPrint.Document.Print(false, false, true);

  • Posted 8 February 2023, 7:27 pm EST

    Hi Chris,

    Thanks for sharing your solution! It will help others doing something similar.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels