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.

Thu Jan 12, 2023 11:23 am

Hi,

i have a huge single pdf and i want to print it in DIN A4 Format.
For that it has to be scaled, keep its aspect ratio and be splitted.
This is my Code so far wich is working but its only for a single page and is not splitting the rest of the page. It just cut it off.

Code: Select all
if (PdfDocument != null)
                {
                    var pdialog = new PrintDialog();
                    if (pdialog.ShowDialog() == DialogResult.OK)
                    {
                        // Costume Scale to print Page Size (DINA4)
                        float costumeScale = PdfDocument.PageSettings.Width / PdfDocument.PrintSettings.PaperSize.Width;

                        PdfDocument.PrintSettings.PrinterName = pdialog.PrinterSettings.PrinterName;
                        PdfDocument.PrintSettings.SelectSinglePageLayout(Spire.Pdf.Print.PdfSinglePageScalingMode.CustomScale, false, (costumeScale * 100));
                        PdfDocument.Print();
                    }
                }


I need something like:

Code: Select all
PdfDocument.PrintSettings.SelectSplitPageLayout(Spire.Pdf.Print.PdfSinglePageScalingMode.CustomScale, false, (costumeScale * 100));


See a sample pdf attached.

Please Help
Greetings
Fabian

FabianLoneberg
 
Posts: 3
Joined: Thu Jan 12, 2023 10:49 am

Fri Jan 13, 2023 10:27 am

Hi,

Thanks for your inquiry.
According to my comprehension, you can see the following code to print the document in DIN A4 Format.
Code: Select all
pdf.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.FitSize);

or
Code: Select all
float widthFitRate = PdfPageSize.A4.Width / pdf.Pages[0].Size.Width;
float heightFitRate = PdfPageSize.A4.Height / pdf.Pages[0].Size.Height;
float fitRate = Math.Min(widthFitRate, heightFitRate);
pdf.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.CustomScale, false, fitRate*100);

if the code doesn’t meet your requirement or you have further questions, you can describe the effect you want to achieve more clearly to help us work out a solution for you. Thanks for your assistance.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Fri Jan 13, 2023 12:59 pm

Hi Triste,
many thanks for your reply.
I'm sorry I didn't express the problem very well.

I wanna scale the pdf to "PdfPageSize.A4.Width" and keep its aspect ratio.
If I do so the resulting pdf should have a height creater than "PdfPageSize.A4.Height".
So i have to split it so multi pages.

Like this, but without throw away the rest.

Code: Select all
                float widthFitRate = PdfPageSize.A4.Width / PdfDocument.Pages[0].Size.Width;
                 PdfDocument.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.CustomScale, false, widthFitRate * 100);

FabianLoneberg
 
Posts: 3
Joined: Thu Jan 12, 2023 10:49 am

Mon Jan 16, 2023 8:25 am

Hi,

Thanks for your feedback.
Please see the following code for reference.
Code: Select all
            float widthFitRate = PdfPageSize.A4.Width / doc.Pages[0].Size.Width;
            float heights = doc.Pages[0].Size.Height * widthFitRate;
            PdfDocument newPdf = new PdfDocument();
            PdfPageBase newPage = newPdf.Pages.Add(new System.Drawing.SizeF(PdfPageSize.A4.Width,heights),new PdfMargins(0));
            newPage.Canvas.ScaleTransform(widthFitRate,widthFitRate);

            newPage.Canvas.DrawTemplate(doc.Pages[0].CreateTemplate(), PointF.Empty);
           
            newPdf.PrintSettings.Landscape = false;         
            newPdf.PrintSettings.SelectPageRange(1, 1);
            newPdf.PrintSettings.SelectSplitPageLayout();
            newPdf.Print();


if the code does not meet your requirement, you can contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Wed Jan 18, 2023 9:27 am

Hi Triste,

thanks for your code. That's roughly what I'm looking for.
But it seems, that the drawing to the canvas is not working correctly ?
The resulting page is empty (See attachment).

Best Regards
Fabian

FabianLoneberg
 
Posts: 3
Joined: Thu Jan 12, 2023 10:49 am

Thu Jan 19, 2023 7:32 am

Hi,

Thanks for your feedback.
I did a test with the code and the latest Spire.PDF (Spire.PDF Pack(Hot Fix) Version:9.1.0), but did not reproduce your issue. I have attached my project and output file, you can download it and import the Spire.PDF.dll, then have a test. In addition, you can try to print with other virtual printers. If the issue still exists after testing, please provide us with the following messages. You could attach them here or send to us via email ([email protected]). Thanks in advance.
1) Your test environment, such as OS info (E.g., Windows 10 64 bit) and region setting (E.g., China, Chinese).
2) The name of the printer you are using.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF

cron