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 Apr 23, 2018 3:22 pm

I need to convert an HTML page that is quite long. Spire.PDF successfully converts the HTML file to a PDF, but the PDF is too long, and is a single page. It is possible to break the HTML page into multiple pages in the PDF? Below is a snip-it of the code I'm using:

string sourceFile = @"C:\Temp\LongHTML\XX1024885.HTM";
string newFile = @"C:\Temp\LongHTML\XXX-DONE-1024885.pdf";
string sourceString = File.ReadAllText(sourceFile);

PdfDocument doc = new PdfDocument();
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();
PdfPageSettings setting = new PdfPageSettings();
setting.Size = PdfPageSize.Letter;

Thread thread = new Thread(() => { doc.LoadFromHTML(sourceString, false, setting, htmlLayoutFormat);});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();

doc.SaveToFile(newFile, FileFormat.PDF);
doc.Close();

System.Diagnostics.Process.Start(newFile);

Thanks for any ideas or solutions you may have.

Nick Solomon

nicksolomon1
 
Posts: 5
Joined: Tue Feb 06, 2018 8:46 pm

Tue Apr 24, 2018 2:09 am

Hello,

Thank you for contacting us.
The LoadFromHTML method provides parameter to auto detect page break, just replace the false with true in your code as below.
Thread thread = new Thread(() => { doc.LoadFromHTML(sourceString, true, setting, htmlLayoutFormat); });

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1385
Joined: Tue Sep 27, 2016 1:06 am

Thu Apr 26, 2018 8:25 am

Hello,

Greetings from E-iceblue!
Is my solution helpful?
Thanks in advance for your valuable feedback and time.

Best wishes,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1385
Joined: Tue Sep 27, 2016 1:06 am

Tue May 01, 2018 3:22 pm

That worked! Thank you again for your quick response and great product!

nicksolomon1
 
Posts: 5
Joined: Tue Feb 06, 2018 8:46 pm

Wed May 02, 2018 1:10 am

Hello,

Glad to hear that.
If you need further assistance, please feel free to contact us.
Wish you a nice day!

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1385
Joined: Tue Sep 27, 2016 1:06 am

Sun Jul 11, 2021 1:56 pm

very usefull for me
but my html includes a big table that not breked into multi pages
is there a way to break also the table

yossi_machshevet.com
 
Posts: 1
Joined: Sun Jul 11, 2021 1:45 pm

Mon Jul 12, 2021 10:34 am

Hello Yossi,

Thanks for your inquiry.
I simulated an HTML file for testing, and found that the table could be paginated successfully. The version I use is the latest Spire.PDF (Spire.PDF Pack (Hot Fix) version: 7.6.15). If you are not using the latest version, I suggest you give it a try.
In addition, we provide QT method to convert HTML to PDF, it is more efficient in producing result with a better effect. Please refer to the following tutorial.
https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Convert-HTML-to-PDF-with-New-Plugin.html
If the problem still exists after trying, please provide the following information to help us further investigate your problem. You could attach them here or send them to us via email ([email protected]). Thanks in advance.
1) Your HTML file.
2) Your full testing code.
3) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).
4) Your application type, such as Console app (. Net Framework 4.5).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Wed Aug 31, 2022 11:46 am

Hi I tired to convert large content containing(html table) html to pdf spire ver 8.8.6.0 without plugins. but generated pdf content not visible completely at position of break the pdf page.
I have attached generated pdf having issue . Please see the attachment and provide the solution.
Thanks.

syed.masoom
 
Posts: 8
Joined: Wed Aug 31, 2022 10:14 am

Thu Sep 01, 2022 6:47 am

Hello syed.masoom,

Thanks for your inquiry.
Generally, the plugins method to convert HTML to PDF has a better performance. You can use this way to have a try. If there is still any issue after testing, in order for us to further investigate your problem, please send us your test documentation. You can attach it here or send it to us via email([email protected]).

Sincerely,
Simple Li
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Thu Sep 01, 2022 2:04 pm

Hi Simple Li,
Thanks for suggestion to use plugins.
I am trying to use plugins with spire.pdf 5.9.16 in my application but I am getting error as below:
The conversion provider cann't be found.
Please make sure the folder "plugins" is under the same folder of Spire.Pdf.dll.

While same html code successfully converted in pdf in desired format using yours's available sample code (HTMLToPDF.zip) in my machine.
But when I am applying same code in my application ,I am getting above error. Also, I have tried with spire.pdf 8.8.6(latest version) but no luck.
I am using visual studio 2017.
Also, 'plugins' folder kept under spire.pdf.dll location.
Could you please suggest me where I am doing mistake.

Thanks.

syed.masoom
 
Posts: 8
Joined: Wed Aug 31, 2022 10:14 am

Fri Sep 02, 2022 7:38 am

Hi Simple Li,
I have found the solution using e-iceblue forum . I have checked 64 bit in tools=>options=>project and solution and ran the code and pdf generated successfully.

One more solution needed- How can we apply header and footer in each page. It would be great if you provide solution.

Thanks.

syed.masoom
 
Posts: 8
Joined: Wed Aug 31, 2022 10:14 am

Fri Sep 02, 2022 9:33 am

Hello syed.masoom,

Glad to hear that you have solved the error issue. Did your Html itself set header and footer in each page? How about the result when you directly convert it by a browser? Our plugin conversion method is based on the Qt plugin of the Chrome kernel, the result effect will be same as the browser does.
Meanwhile, our Spire.PDF supports adding header and footer on PDF file, you can refer to the below links. If there is still any problems, please share us with your Html file as well as your desired output effect for further investigation. You can attach them here or send them via email([email protected]).
https://www.e-iceblue.com/Tutorials/Spi ... B.NET.html
https://www.e-iceblue.com/Tutorials/Spi ... B.NET.html

Sincerely,
Simple Li
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Fri Sep 02, 2022 1:19 pm

Hi Simple Li,
Thanks for your support!

Now I am able to apply footer in pdf.

Thanks
Syed Masoom

syed.masoom
 
Posts: 8
Joined: Wed Aug 31, 2022 10:14 am

Mon Sep 05, 2022 9:53 am

Hello syed.masoom,

Thanks for your reply.
I'm glad to hear that your problem has been solved. If you have any further questions, please feel free to contact us.

Sincerely,
Simple Li
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Return to Spire.PDF