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 Aug 08, 2024 11:20 am

Hi Team,

Good morning!
i am looking for HTML to PDF conversion without plugin.
Spire PDF version : 10.7.21

Followed below sample, which is download from your sample code

Code: Select all
using Spire.Pdf;
using Spire.Pdf.HtmlConverter;
using System.IO;
using System.Threading;
using System.Drawing;

namespace ConvertHtmlStringToPdfWithoutPlugin
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument object
            PdfDocument doc = new PdfDocument();

            //Create a PdfPageSettings object
            PdfPageSettings setting = new PdfPageSettings();

            //Save page size and margins through the object
            setting.Size = new SizeF(1000, 1000);
            setting.Margins = new Spire.Pdf.Graphics.PdfMargins(20);

            //Create a PdfHtmlLayoutFormat object
            PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();

            //Set IsWaiting property to true
            htmlLayoutFormat.IsWaiting = true;

            //Read html string from a .html file
            string htmlString = File.ReadAllText(@"C:\Users\Administrator\Desktop\Document\Html\Sample.html");

            //Load HTML from html string using LoadFromHTML method
            Thread thread = new Thread(() =>
            { doc.LoadFromHTML(htmlString, true, setting, htmlLayoutFormat); });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            //Save to a PDF file
            doc.SaveToFile("HtmlStringToPdf.pdf");
        }
    }
}


Getting below erros

using Spire.Pdf.HtmlConverter; - namespace Htmlconverter not fould
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat(); - PDFHTMLLayoutFormat could not be found
doc.LoadFromHTML(htmlString, true, setting, htmlLayoutFormat); - LoadFromHtml could not be found

Here I have attached console app.

Could you please check and help us

Thanks
kannan

kannangandhi
 
Posts: 4
Joined: Fri Nov 25, 2022 2:25 pm

Fri Aug 09, 2024 8:28 am

Hello,

Thanks for your inquiry.The method you used is no longer used and maintained in the new version. Currently, we recommend using the following new way to convert HTML to PDF. You can refer to the code below.If you have any other questions, please feel free to write to me.

Code: Select all
//The installation location of your Chrome browser
   string chromeLocation = baseDirectory +"chrome.exe";
            ChromeHtmlConverter converter = new ChromeHtmlConverter(chromeLocation);
            ConvertOptions options = new ConvertOptions();
            options.Timeout = 10 * 1000;
            options.PageSettings = new PageSettings()
            {
                PaperWidth = 8.77,
                PaperHeight = 6.20,
                MarginBottom = 0,
                MarginTop = 0,
                MarginLeft = 0,
                MarginRight = 0
            };
            converter.ConvertToPdf("https://www.e-iceblue.cn/", "HtmlToPdf.pdf", options);

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 277
Joined: Mon Jul 15, 2024 5:40 am

Thu Sep 05, 2024 7:41 am

Hi Team,

We are currently in the process of migrating our application to .NET 8. Since we have a valid license for your product, we are seeking a solution that does not rely on any plugins for this migration. Could you please provide guidance or an alternative approach that would allow us to integrate your solution seamlessly into our .NET 8 application?

Your assistance in helping us navigate this migration without the need for additional plugins would be greatly appreciated. We look forward to your recommendations.

Thanks
Kannan

kannangandhi
 
Posts: 4
Joined: Fri Nov 25, 2022 2:25 pm

Fri Sep 06, 2024 2:41 am

Hello,

Thanks for your inquiry.
For the net8.0 platform, we currently mainly use and maintain the 'ChromeHtmlConverter' method. Sorry, at present, Spire.PDF does not have other methods that didn't rely on any third plugins. Thank you for your understanding.
Additionally, our Spire.Doc(https://www.e-iceblue.com/Tutorials/Spire.Doc/Spire.Doc-Program-Guide/How-to-Convert-HTML-to-XML-in-C-and-VB.NET.html) includes a method to convert HTML to PDF without using any plugins, you can test your documents.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 277
Joined: Mon Jul 15, 2024 5:40 am

Mon Sep 09, 2024 6:44 am

Thank you for the information regarding the ChromeHtmlConverter method and Spire.PDF.

We already hold a license for Spire.PDF. Regarding Spire.Doc, specifically the method for converting HTML to PDF without third-party plugins, could you please confirm if a separate license is required to use this feature?

Thank you for your assistance.

kannangandhi
 
Posts: 4
Joined: Fri Nov 25, 2022 2:25 pm

Tue Sep 10, 2024 2:54 am

Hello,

Thank you for your feedback.Spire.doc and Spire.pdf are two separate products, and if you want to use Spire.doc, you need a separate license.If there is still any doubts, you can feel free to write back.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 277
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.PDF