We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Print PDF file using C# and Aspose.PDF | Number of copies are multiplied when printing via Microsoft Print to PDF printer

Hi,

I am using the following code to print pdf files from stream. The problem that number of copies that actually printed is multiplied. For example if I am printing 2 copies then 4 copies is printed instead (9 instead of 3 and so on…). I don’t have a physical/network printer connected to my PC so I am using Microsoft Print to PDF printer.

The problem still exists when using latest 21.3.0.0 version.

I found old topics Copies from PrinterSettings is not working during print where it was said that the issue was fixed but it still happens.

Need help!

ps.Copies = (short)numberOfCopies;

        using (var stream = new MemoryStream(content[0]))
        {
            using (PdfViewer viewer = new PdfViewer())
            {
                viewer.BindPdf(stream);
                viewer.PrintDocumentWithSettings(ps);
                viewer.Close();
            }
        }

Thanks
Stanislav

@stanlys2

Would you please share a complete sample code snippet for our reference which includes the specified PrinterSettings? We will test the scenario in our environment accordingly and share our feedback with you.

Sure. It happens always. This is enough:

        System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();

        ps.Copies = (short)numberOfCopies;

        using (var stream = new MemoryStream(content[0]))
        {
            using (PdfViewer viewer = new PdfViewer())
            {
                viewer.BindPdf(stream);
                viewer.PrintDocumentWithSettings(ps);
                viewer.Close();
            }
        }

@stanlys2

We tested with the Aspose.PDF for .NET 21.3 and the below sample code snippet in our environment. We did not notice any issue. Only one copy of the printed document was generated in the output directory:

using (Facades.PdfViewer pdfViewer = new Facades.PdfViewer())
{
 pdfViewer.BindPdf(dataDir + "signed.pdf");
 System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
 ps.PrinterName = "Microsoft Print to PDF";
 ps.Copies = 1;
 pdfViewer.PrintDocumentWithSettings(ps);
 pdfViewer.Close();
}

Can you please make sure that the above property is being set correctly at your end. In case issue still persists, please share a sample console application in .zip format with us so that we can again test the scenario in our environment and address it accordingly.

That is correct. When setting number of copies to 1 indeed only one copy is printed (that what I wrote in the issue, number of copies is multiplied, means 1X1=1, 2X2=4, 3X3=9). Please set number of copies to larger than 1, for example 2 and check how many copies will be printed.

Thanks
Stanislav

@stanlys2

Sorry for the confusion. Yes, you are right. We were now able to reproduce the issue. Hence, have logged it as PDFNET-49658 in our issue tracking system. We will further investigate the reasons behind this issue and let you know as soon as it is rectified. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thanks! Can you say if this issue is only when printing via Microsoft Print to PDF printer or it also happens when printing to the physical printer?

@stanlys2

We will further review the ticket and as soon as its analysis is complete, we will share further details with you. Please give us some time.

We apologize for the inconvenience.

Hi,

What is the status of this item?

@stanlys2

We are afraid that the earlier logged ticket could not get resolved due to other issues reported previously. However, we will surely inform you as soon as we have some definite updates regarding ticket resolution. Please spare us some time.

We are sorry for the inconvenience.