Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Sun Apr 05, 2020 12:21 pm

I'm developing a software that print A3 documents.
If i print document with virtual printers, like pdf printer of Mircrosoft, margins are correct.
Instead, if i print files on a real printer, margins are wrong and they are less or bigger compared to original pdf.
here there is my code:
Code: Select all
  private void PrintListe(string Formato, int Npagine)
        {


            int minP = 0, maxP = 0;


            if (Formato == "Fronte")
            {
                minP = 1;
                maxP = 1;
            }
            if (Formato == "Retro")
            {
                minP = 2;
                maxP = 2;
            }
            int nstampa = 0;
            do
            {

                if (Formato == "Fronte-Retro")
                {
                    minP = 1;
                    maxP = 2;
                    var docum = new PdfDocument(@"Tmp/list" + nstampa + ".pdf");
                    docum.Pages.ReArrange(new int[] { 1, 0 });

                    docum.SaveToFile(@"Tmp/list" + nstampa + ".pdf");

                    docum.Close();

                }
                PdfDocument doc = new PdfDocument();
                doc.LoadFromFile(@"Tmp/list" + nstampa + ".pdf");
                doc.PrintFromPage = minP;
                doc.PrintToPage = maxP;
                doc.PrinterName = Pagine.Impostazioni.getPrinterName();


                PaperSize paper = new PaperSize("A3", (int)PdfPageSize.A3.Width, (int)PdfPageSize.A3.Height);
                paper.RawKind = (int)PaperKind.A3;
                switch (Pagine.Impostazioni.getPaperSize())
                {

                    case "A2":
                        {
                            paper = new PaperSize("A2", (int)PdfPageSize.A2.Width, (int)PdfPageSize.A2.Height);
                            paper.RawKind = (int)PaperKind.A2;
                            break;
                        }
                    case "A3":
                        {
                            paper = new PaperSize("A3", (int)PdfPageSize.A3.Width, (int)PdfPageSize.A3.Height);
                            paper.RawKind = (int)PaperKind.A3;
                            break;
                        }
                    case "A4":
                        {
                            paper = new PaperSize("A4", (int)PdfPageSize.A4.Width, (int)PdfPageSize.A4.Height);
                            paper.RawKind = (int)PaperKind.A4;
                            break;
                        }
                    case "A5":
                        {
                            paper = new PaperSize("A5", (int)PdfPageSize.A5.Width, (int)PdfPageSize.A5.Height);
                            paper.RawKind = (int)PaperKind.A5;
                            break;


                        }
                    case "A6":
                        {
                            paper = new PaperSize("A6", (int)PdfPageSize.A6.Width, (int)PdfPageSize.A6.Height);
                            paper.RawKind = (int)PaperKind.A6;
                            break;
                        }
                }


                  doc.PrintDocument.DefaultPageSettings.PaperSize = paper;
                  doc.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.ActualSize, false);

                  doc.PrintDocument.PrintController=new  StandardPrintController();
             
                  PrintDocument printDoc = doc.PrintDocument;
                printDoc.DefaultPageSettings.Margins.Left =0;
                printDoc.DefaultPageSettings.Margins.Right = 0;
                printDoc.DefaultPageSettings.Margins.Top = 0;
                printDoc.DefaultPageSettings.Margins.Bottom = 0;
                printDoc.PrinterSettings.DefaultPageSettings.Margins.Left = 0;
                printDoc.PrinterSettings.DefaultPageSettings.Margins.Right = 0;
                printDoc.PrinterSettings.DefaultPageSettings.Margins.Top = 0;
                printDoc.PrinterSettings.DefaultPageSettings.Margins.Bottom = 0;
                printDoc.DocumentName= "list" + nstampa + ".pdf";


                printDoc.Print();

                doc.Close();
                nstampa++;
            } while (nstampa < Npagine);



        }

here there is the gap between orginal file and the printed file:
Orginal PDF:front 1,7sx 15,5h - back 1,7sx e 4,7h
Printed File:front1,9sx (+2) 15,65h (+1,5) - back 1,9sx (+2) 5,1h (+4)

cadons_pdf
 
Posts: 5
Joined: Wed Mar 11, 2020 6:46 pm

Mon Apr 06, 2020 3:53 am

Hi,

Thanks for your post.
I used your code to do a preliminary test with a A3 pdf document but didn't reproduce the issue you mentioned. I am using Spire.PDF Pack(Hot Fix) Version:6.3.16, which is the latest Spire.PDF now.
In order to help us reproduce and investigate the issue, could you please share a A3 pdf document you used with us? And please also tell us what printer you used.

Thanks for your assistance in advance.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Apr 06, 2020 8:28 pm

ok the printer is Epson wf 7515. i have attached pdf file.
This pdf has got right margins but if i print with spirePDF class they are wrong on paper but if i print in pdf they are right

cadons_pdf
 
Posts: 5
Joined: Wed Mar 11, 2020 6:46 pm

Tue Apr 07, 2020 7:00 am

Hi,

Thanks for providing further information.
Are you using Spire.PDF Pack(Hot Fix) Version:6.3.16?
Sorry, we don't have Epson wf 7515 printer. But I still didn't reproduce the margins issue when I tested your pdf file using HP printers.
Please try the below code and give us your test results.
Code: Select all
PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("D:/list0.pdf");
            PaperSize paper = new PaperSize("A3", (int)PdfPageSize.A3.Width, (int)PdfPageSize.A3.Height);
            paper.RawKind = (int)PaperKind.A3;
            pdf.PrintSettings.PaperSize = paper;
            pdf.PrintSettings.SetPaperMargins(0, 0, 0, 0);
            pdf.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.ActualSize, false,100f);
            pdf.Print();

If the above code can't work, could you please try your other printers in order to help us know if it is related to printer?

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Apr 07, 2020 7:21 am

Now i'm going to try your code,
I used FreeSpirePDF, now i'm trying your package but have you mesured the margins because the differences are for millimiter.
Can you check this differences on the pdf and the paper.

cadons_pdf
 
Posts: 5
Joined: Wed Mar 11, 2020 6:46 pm

Tue Apr 07, 2020 10:07 am

Hi,

Have you tested my code and tried my package?
I separately measured the top, bottom, left, and right blank area on the pdf and the paper. There is no differences between them.
If my code and package don't help, please share your printing result so that we can see the differences you mentioned.
In addition, please also tell me your system environment. Would you mind trying Microsoft XPS Document Writer virtual printer to check if the result is correct?

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Apr 07, 2020 10:46 am

I'm working for a customer and he has got the printer. he said me that this evening he will try print. I will give you futher information tomorrow. Code works also with on xps printer and sized are right, now i'm waiting the printer on paper

cadons_pdf
 
Posts: 5
Joined: Wed Mar 11, 2020 6:46 pm

Wed Apr 08, 2020 2:09 am

Hi,

Thanks for your feedback.
Looking forward to hear from you again.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Apr 08, 2020 6:39 am

My customer has confirmed that code works properly, thank you so much, i have thought that the problem was PrintDocument, but i couldn't found an alterative. Thank you so much

cadons_pdf
 
Posts: 5
Joined: Wed Mar 11, 2020 6:46 pm

Wed Apr 08, 2020 7:04 am

Hi,

Thanks for your feedback.
I am glad hear that it works.
Feel free to contact us if you need any other help.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF