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 Nov 20, 2017 12:54 pm

I'm using Spire.PDF to convert HTML into PDF, but when the html is too wide, it cuts out the parts it can't contain/constrain.

I'm using the default code supplied on your website. Is there a way to constrain/resize the HTML to fit on A4 pdf?

raijinakruo
 
Posts: 5
Joined: Mon Oct 16, 2017 2:04 pm

Tue Nov 21, 2017 2:49 am

Hello raijinakruo,

Thanks for your inquiry.
If the html page is too wide, I'm afraid you need to set the pdf page size accordingly.
Please refer to the code below.
Code: Select all
 
        PdfDocument doc = new PdfDocument();
        PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();
        htmlLayoutFormat.IsWaiting = false;
        var settings = new PdfPageSettings();
        settings.Size = PdfPageSize.A3;// set the page size accordingly.
        Thread thread = new Thread(() =>
        {
            doc.LoadFromHTML(fileName, false, settings, htmlLayoutFormat);
        });
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();
        thread.Join();
        doc.SaveToFile(resultName, FileFormat.PDF);


Sincerely,
Jane
E-iceblue support team
User avatar

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

Fri Nov 24, 2017 8:33 am

Hi raijinakruo,

Greetings from e-iceblue!
Have you tried the solution?
Your feedback will be greatly appreciated.

Sincerely,
Jane
E-iceblue support team
User avatar

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

Wed Jan 03, 2018 10:29 pm

Hi,

The solution helped but we decided not to go with it as the html might require the page size to be larger and larger, so we've left it as the default.

Thanks for your assistance.

raijinakruo
 
Posts: 5
Joined: Mon Oct 16, 2017 2:04 pm

Thu Jan 04, 2018 1:32 am

Hello raijinakruo,

Thanks for your feedback.
Any problem, welcome to write back.

Sincerely,
Jane
E-iceblue support team
User avatar

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

Return to Spire.PDF

cron