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 09, 2018 3:48 pm

Hello,

I recieve a PDF-document with 4 x 6in.
When I print through Spire.PDF, the pagesize of the printed PDF is always 8.5 x 11in.

I've tried with both PageScaling-settings (FitSize & ActualSize). But it does not deliver the desired effect.
The page size of the final print should be based on the page size of the original received PDF (4x6in).

Using PageScaling-settings, the content of the PDF is either scaled onto 8.5x11in or the original scaling is provided, but the Page Size is 8.5x11in/

How can I solve this problem?

Kind regards,
Hannes

HannesHolst
 
Posts: 4
Joined: Mon Jul 09, 2018 3:33 pm

Tue Jul 10, 2018 3:59 am

Hi Hannes,

Thank you for your post.
We have made some modifications to the print method. Please upgrade to the latest hotfix(Spire.PDF Pack(Hot Fix) Version:4.6.8) and use the following code to accomplish your task.
Code: Select all
Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();
doc.LoadFromFile(FileName);
doc.PrintSettings.SelectSinglePageLayout(Spire.Pdf.Print.PdfSinglePageScalingMode.ActualSize);
doc.Print();

If the issue still troubles you, please share your sample document.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Jul 10, 2018 9:17 am

Hi Jane,

Thanks for your reply.
Please see the attachments for the current result. The scaling is fine, but the pagesize is still 8.5x11in.

Here is the code:
Code: Select all
Spire.Pdf.PdfDocument PdfPrint= new Spire.Pdf.PdfDocument();
PdfPrint.LoadFromFile('Original PDF.pdf');
PdfPrint.PrintSettings.SelectSinglePageLayout(Spire.Pdf.Print.PdfSinglePageScalingMode.ActualSize);
PdfPrint.Print;
PdfPrint.Dispose;


Do you have an idea which setting I should amend?

Kind regards,
Hannes

HannesHolst
 
Posts: 4
Joined: Mon Jul 09, 2018 3:33 pm

Tue Jul 10, 2018 11:16 am

Hi Hannes,

If you want to maintain the page size, please use the following code.
Code: Select all
Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();
doc.LoadFromFile(FileName);

SizeF size = doc.Pages[0].Size;

PaperSize paper = new PaperSize("Custom", (int)size.Width/72*100, (int)size.Height/72*100);
paper.RawKind = (int)PaperKind.Custom;
doc.PrintSettings.PaperSize = paper;
doc.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.FitSize, true);
doc.Print();


Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Jul 10, 2018 12:38 pm

Hi Jane,

Thanks for your response.
I'm using following code.
Code: Select all
Spire.Pdf.PdfDocument PdfPrint= new Spire.Pdf.PdfDocument();
PdfPrint.LoadFromFile('Original PDF.pdf');

SizeF = PdfPrint.PageSettings.Size;
PaperSize = PaperSize.PaperSize("custom", (int)SizeF.Width/72*100, (int)SizeF.Height/72*100);

PdfPrint.PrintSettings.PaperSize(PaperSize);
PdfPrint.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.ActualSize);

PdfPrint.Print;
PdfPrint.Dispose;


The page size of the file "Orginal PDF.pdf" (you can find attached in the earlier post) is 4x6in.
When printing with above code, the printed page size is 8.27x11.69in.
Spire.PDF returns "SizeF.Width = 595" and "SizeF.Height = 842" which converts into Widt = 826 and Height = 1169.

When I apply
Code: Select all
PaperSize = PaperSize.PaperSize("custom", 400, 600);

I get the correct page size in the print out.

Could you load the attached "Orginal PDF.pdf" into a PdfDocument-instance and validate the correct Width and Height?

Kind regards,
Hannes

HannesHolst
 
Posts: 4
Joined: Mon Jul 09, 2018 3:33 pm

Tue Jul 10, 2018 4:04 pm

Hi,

Don't mind this request anymore.
I think I've found the solution now.
There was a bug in my code and the "Microsoft Print to PDF"-printer (which I use for the print out) does ignore the page size of the original document.

Thanks.

HannesHolst
 
Posts: 4
Joined: Mon Jul 09, 2018 3:33 pm

Wed Jul 11, 2018 1:58 am

Hello Hannes,

Thank you for your feedback.
You got the wrong page size because your code is different from that I provided.
Anyway, glad to hear that you have worked it out.
Just feel free to contact us if you need any assistance.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.PDF