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.

Mon Jul 30, 2018 5:42 am

I'm trying to print out a pdf in both A3 and A4.

Using the following code:

private void PrintFile(string FullPath, bool colour = false, bool A3 = false, short Quantity = 1)
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(FullPath);
doc.PrintSettings.PrinterName = PrinterCB.Text;
PaperSize paper;
if (A3)
{
paper = new PaperSize("A3", (int)PdfPageSize.A3.Width, (int)PdfPageSize.A3.Height)
{
RawKind = (int)PaperKind.A3
};
doc.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.FitSize, true, 100f);
}
else
{
paper = new PaperSize("A4", (int)PdfPageSize.A4.Width, (int)PdfPageSize.A4.Height)
{
RawKind = (int)PaperKind.A4
};
doc.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.FitSize, true, 100f);
}
doc.PrintSettings.PaperSize = paper;

doc.PrintSettings.Copies = Quantity;

doc.PrintSettings.Color = colour;

doc.PrintSettings.Collate = true;

PrintController printController = new StandardPrintController();
doc.PrintSettings.PrintController = printController;
doc.Print();
}

However in both A3 and A4 it is only using 70% of the page - see attached.

I can't workout what I am doing wrong. Any help you can give me would be appreciated.

robparmenter
 
Posts: 2
Joined: Fri Aug 07, 2015 2:41 am

Mon Jul 30, 2018 10:10 am

Hello,

Thank you for your post.
The issue is caused by the difference of default unit for PaperSize and PdfPageSize. Kindly note that the default unit of PaperSize is 100 inch, while the default unit of PdfPageSize is point. Therefore, the conversion of unit is necessary. Please refer to the code below.
Code: Select all
private void PrintFile(string FullPath, bool colour = false, bool A3 = false, short Quantity = 1)
{
    PdfDocument doc = new PdfDocument();
    doc.LoadFromFile(FullPath);
    doc.PrintSettings.PrinterName = PrinterCB.Text;
    PaperSize paper;
    if (A3)
    {
        paper = new PaperSize("A3", (int)(PdfPageSize.A3.Width / 72 * 100), (int)(PdfPageSize.A3.Height/ 72 * 100))
        {
            RawKind = (int)PaperKind.A3
        };
        doc.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.FitSize, true, 100f);
    }
    else
    {
        paper = new PaperSize("A4", (int)(PdfPageSize.A4.Width / 72 * 100), (int)(PdfPageSize.A4.Height / 72 * 100))
        {
            RawKind = (int)PaperKind.A4
        };
        doc.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.FitSize, true, 100f);
    }
    doc.PrintSettings.PaperSize = paper;

    doc.PrintSettings.Copies = Quantity;

    doc.PrintSettings.Color = colour;

    doc.PrintSettings.Collate = true;

    PrintController printController = new StandardPrintController();
    doc.PrintSettings.PrintController = printController;
    doc.Print();
}

If there is any problem, please feel free contact us.
Sincerely,
Hogan
E-iceblue support team
User avatar

hogan.tang
 
Posts: 51
Joined: Tue Jul 03, 2018 1:43 am

Tue Jul 31, 2018 5:02 am

Thank you so much. That worked perfectly.

robparmenter
 
Posts: 2
Joined: Fri Aug 07, 2015 2:41 am

Tue Jul 31, 2018 8:35 am

Hi,

Thanks for your feedback.
Just feel free to contact us if you have any question.
Have a nice day.
Sincerely,
Hogan
E-iceblue support team
User avatar

hogan.tang
 
Posts: 51
Joined: Tue Jul 03, 2018 1:43 am

Return to Spire.PDF