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 Mar 01, 2021 8:43 pm
Hello
I am looking for an example in the latest version of Sprire.PDF for .Net v7.2.9., to convert HTML string to PDF. In the 7 overloads for the Converter method, it is looking for a URL. No way to pass in HTML String?
Also, I am evaluating your product to be able to do the following:
1. Convert HTML string to PDF
2. Be able to append multiple HTML Strings to a PDF document
If you need any more information on my project let me know.
Would appreciate an example on converting HTML string to PDF.
Tom
-

tmeschede
-
- Posts: 1
- Joined: Mon Mar 01, 2021 8:12 pm
Tue Mar 02, 2021 2:27 am
Hello,
Thanks for your inquiry!
Please refer to the following code to convert HTML string to PDF and append multiple HTML strings to a PDF document.
- Code: Select all
//convert HTML string to PDF:
string file = "htmlcode.txt";
string code = File.ReadAllText(file);
string filepath = "HTMLCodetoPdf.pdf";
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.PluginPath = @"path";
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(code,
filepath,
false,
200,
new System.Drawing.SizeF(612, 792),
new Spire.Pdf.Graphics.PdfMargins(0),
LoadHtmlType.SourceCode);
- Code: Select all
//append multiple HTML strings to a PDF:
string file = "htmlcode.txt";
string code = File.ReadAllText(file);
string code2 = "This demo shows how we can insert <u><i>HTML styled text</i></u> to PDF using "
+ "<font color='#FF4500'>Spire.PDF for .NET</font>. "
PdfDocument pdf = new PdfDocument();
PdfNewPage page = pdf.Pages.Add() as PdfNewPage;
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 5);
PdfBrush brush = PdfBrushes.Black;
PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(code, font, brush);
PdfHTMLTextElement richTextElement2 = new PdfHTMLTextElement(code2, font, brush);
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Layout = PdfLayoutType.Paginate;
format.Break = PdfLayoutBreakType.FitPage;
//Draw htmlString
richTextElement.Draw(page, new RectangleF(0, 20, 200, 200), format);
richTextElement2.Draw(page, new RectangleF(0, 220, 200, 200), format);
pdf.SaveToFile("Output.pdf");
If the code does not meet your needs, please provide us with your HTML strings and the expected output for further investigation. Thanks in advance.
Sincerely,
Marcia
E-iceblue support team
-


Marcia.Zhou
-
- Posts: 858
- Joined: Wed Nov 04, 2020 2:29 am
Mon Mar 22, 2021 8:05 am
Hello,
Hope you are doing well!
How is the issue now? If it still exists, could you please provide your HTML strings and the expect output to us for further investigation?
Thanks in advance.
Sincerely,
Marcia
E-iceblue support team
-


Marcia.Zhou
-
- Posts: 858
- Joined: Wed Nov 04, 2020 2:29 am