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 Feb 13, 2025 9:35 am

Trial 1 :
Code: Select all
 
var templateFile = "<SomePath>/temp.html";
var template = string.Empty;

            using (var sw = new StreamReader(templateFile.OpenReadStream()))
            {
                //sw.BaseStream.Seek(0, SeekOrigin.End);
                template = sw.ReadToEnd();
            }

var ms = new MemoryStream();
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(template, ms, true, 10000, Spire.Pdf.PdfPageSize.A4, new Spire.Pdf.Graphics.PdfMargins(0), Spire.Pdf.HtmlConverter.LoadHtmlType.SourceCode);
var pdf = new Spire.Pdf.PdfDocument(ms);


Trial 2 :
Code: Select all
 
var templateFile = "<SomePath>/temp.html";
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(templateFile,"<OutputPath>/temp.pdf", true, 10000, Spire.Pdf.PdfPageSize.A4, new Spire.Pdf.Graphics.PdfMargins(0), Spire.Pdf.HtmlConverter.LoadHtmlType.URL);

var pdf = new Spire.Pdf.PdfDocument("<OutputPath>/temp.pdf");


Both new Spire.Pdf.PdfDocument() giving error :
Trial 1 : index was outside the bounds of the array
Trial 2 : File doesnt exist (the pdf file never generated after calling HtmlConverter.Convert

**Both trial working fine in windows laptop and server without latest patching (8th Feb 2025)
**Tried with latest plugins download from E-Iceblue
**Unable try with latest spire.pdf version (11.2.4) as it not longer support HtmlConverter class
**From Windows logs, the error are throwing from Html2Pdf.exe

OS : Windows Server 2019
Spire.pdf version 9.3.4


Hi,

Would like to get advise for issue above, or is there any alternative solution for converting HTML to PDF?
*Since 11.2.4 version not longer support HtmlConverter, is there any new approach for this conversion?

cgscimbspire
 
Posts: 8
Joined: Wed Jan 04, 2023 8:34 am

Thu Feb 13, 2025 10:12 am

Hi,

Thanks for your inquiry.
In the new version, we have upgraded the namespace of HtmlConverter from the Spire.Pdf.HmlConverter.Qt to Spire.Additions.Qt, please change your code as below.
Code: Select all
Spire.Additions.Qt.HtmlConverter.Convert(template, ms, true, 10000, Spire.Pdf.PdfPageSize.A4, new Spire.Pdf.Graphics.PdfMargins(0), Spire.Additions.Qt.LoadHtmlType.SourceCode);

Besides, adove method uses QT to do the conversion. Please note the QT has a high dependency on the environment, it may result in the inability to output the result PDF in some cases. We provide a new class ChromeHtmlConverter to convert HTML to PDF using chrome.exe, eliminating the need for QT plugin. Please download the latest version of Spire.PDF (Spire.PDF Pack(Hot Fix) Version:11.2.4) and refer to this tutorial to have a try: Convert HTML to PDF using ChromeHtmlConverter

Sincerely,
Nina
E-iceblue support team
User avatar

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

Fri Feb 14, 2025 3:36 am

Nina.Tang wrote:Hi,

Thanks for your inquiry.
In the new version, we have upgraded the namespace of HtmlConverter from the Spire.Pdf.HmlConverter.Qt to Spire.Additions.Qt, please change your code as below.
Code: Select all
Spire.Additions.Qt.HtmlConverter.Convert(template, ms, true, 10000, Spire.Pdf.PdfPageSize.A4, new Spire.Pdf.Graphics.PdfMargins(0), Spire.Additions.Qt.LoadHtmlType.SourceCode);

Besides, adove method uses QT to do the conversion. Please note the QT has a high dependency on the environment, it may result in the inability to output the result PDF in some cases. We provide a new class ChromeHtmlConverter to convert HTML to PDF using chrome.exe, eliminating the need for QT plugin. Please download the latest version of Spire.PDF (Spire.PDF Pack(Hot Fix) Version:11.2.4) and refer to this tutorial to have a try: Convert HTML to PDF using ChromeHtmlConverter

Sincerely,
Nina
E-iceblue support team



Hi Nina,

i tried the chrome convert, when i open the converted pdf in browser, the tab name tend to be the html file name that used in conversion instead of the pdf file name

cgscimbspire
 
Posts: 8
Joined: Wed Jan 04, 2023 8:34 am

Fri Feb 14, 2025 8:03 am

Hi,

Thanks for your feedback.
I haven't encountered your problem. The ChromeHtmlConverter fully utilizes Google Chrome to render PDF document. You can use your Google Chrome broswer to open your HTML file and press the shortcut Ctrl+P to check if the printed PDF has this behavior. Maybe you can provide your HTML file to help us better investigate it, you can upload it here or send to my email ([email protected]).

Sincerely,
Nina
E-iceblue support team
User avatar

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

Fri Feb 14, 2025 8:59 am

Nina.Tang wrote:Hi,

Thanks for your feedback.
I haven't encountered your problem. The ChromeHtmlConverter fully utilizes Google Chrome to render PDF document. You can use your Google Chrome broswer to open your HTML file and press the shortcut Ctrl+P to check if the printed PDF has this behavior. Maybe you can provide your HTML file to help us better investigate it, you can upload it here or send to my email ([email protected]).

Sincerely,
Nina
E-iceblue support team



Hi Nina,

We couldn't run it on servers, it neither throw error nor generating the pdf, however in event log, we notice it capture this from chrome whenever we run "[9856:1056:0214/163949.156:INFO:rlz_lib.cc(448)] Failed sending RLZ".

But it run without issue in my laptop, same chrome version, does it require internet to run? or any requirement we could missed?

By the way, i am converting the html to pdf in memory and password protect it then save it again as PDF, so when i open the saved PDF with browser, the tab above actually showing the html file name

Code: Select all
var ms = new MemoryStream();
converter.ConvertToPdf($"{dir}/test.html", ms, options);
 var pdf = new Spire.Pdf.PdfDocument(ms);
//some operation
 pdf.SaveToFile("output.pdf", Spire.Pdf.FileFormat.PDF);
 ms.Close();


When i open output.pdf via browser, it show "test.html" on the browser tab

cgscimbspire
 
Posts: 8
Joined: Wed Jan 04, 2023 8:34 am

Fri Feb 14, 2025 10:01 am

Hi,

Thanks for your feedback.
This method doesn't require internet. Below is my answers to your two questions.
1. Based on your error log, we are unable to determine the issue. I speculate that the possible reason may be that your chrome.exe file is being used. You can try my Google version directly. If the problem still persists, please provide the following information to help us better investigate your issue.
a) The error log
b) Your test.html file
c) Detailed information about your server, such as Windows 10, 64bit

2. Testing your code still cannot reproduce the issue, further investigation is still needed with your test.html file.

Sincerely,
Nina
E-iceblue support team
User avatar

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

Return to Spire.PDF