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.

Fri Oct 06, 2017 4:29 pm

Is there any comprehensive documentation on what aspects of HTML are supported by the PdfHTMLTextElement class? I'm looking to use this class to write to existing PDF pages (PDF doc loaded from a substrate PDF file).

The only example I have come across is https://www.e-iceblue.com/Tutorials/Spi ... B.NET.html . This example does not work for me ... does not yield formatted PDF text ... the inserted text has no underline and no italics. I'm also hoping to do much more than is demonstrated in this example ... hoping that PdfHTMLTextElement supports more sophisticated and complex HTML. It looks like it supports div with inline styling to state margins. But once again not have any luck with the span styling for bold, underline or italics.

shaunlandau
 
Posts: 10
Joined: Mon Jul 21, 2014 4:39 pm

Fri Oct 06, 2017 4:34 pm

Actually I was mistaken. The div margins are not working either :(

shaunlandau
 
Posts: 10
Joined: Mon Jul 21, 2014 4:39 pm

Fri Oct 06, 2017 4:47 pm

I'm using Spire.PDF 3.5.51.5040 .

shaunlandau
 
Posts: 10
Joined: Mon Jul 21, 2014 4:39 pm

Fri Oct 06, 2017 4:49 pm

This is my C# code:

htmlTemplate = @"This demo shows how we can insert <span style=""text-decoration: underline; ""><em>HTML styled text</em></span> to PDF using <span style=""color: #ff4500;"">Spire.PDF for .NET</span>.";
doc = new PdfDocument();
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 5);
PdfBrush brush = PdfBrushes.Black;
PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(htmlTemplate, font, brush);
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Layout = PdfLayoutType.Paginate;
format.Break = PdfLayoutBreakType.FitPage;
var page = doc.Pages.Add() as PdfNewPage;
richTextElement.Draw(page, new RectangleF(0, 20, page.GetClientSize().Width, page.GetClientSize().Height), format);
doc.SaveToFile(@"c:\Temp\" + Guid.NewGuid().ToString() + ".pdf");
Last edited by shaunlandau on Fri Oct 06, 2017 4:51 pm, edited 1 time in total.

shaunlandau
 
Posts: 10
Joined: Mon Jul 21, 2014 4:39 pm

Fri Oct 06, 2017 4:50 pm

This is what I'm seeing in the generated PDF file.

shaunlandau
 
Posts: 10
Joined: Mon Jul 21, 2014 4:39 pm

Mon Oct 09, 2017 3:29 am

Dear shaunlandau,

Sorry for late reply as weekend.
I have noticed the issue you mentioned and posted it to our Dev team. Once there is any progress, we will let you know.
In addition, there are three solutions could convert HTML code to PDF, maybe you could use one of them to solve your issue.
1)LoadFromHTML method in Spire.PDF.
https://www.e-iceblue.com/Tutorials/Spi ... -in-C.html
2)The plugin with Spire.PDF
https://www.e-iceblue.com/Tutorials/Spi ... lugin.html
3)First use Paragraph.AppendHTML mehtod to load HTML then save to PDF using Spire.Doc.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Oct 10, 2017 9:02 pm

Thanks Betsy. I need to start from a PDF file, not from an HTML file or a Word file. I need to add content to an existing PDF file. I don't think these options you have suggested allow me to do that. My program is intended to accomplish data-driven insert of content into a PDF file. Until now that content was simple in terms of formatting however business requirements have changed and so I was hoping I could leverage HTML features of the Spire.PDF tool set. My fingers are crossed ... I hope this feature is actually useful since I want to avoid manual coding of content via C#.

shaunlandau
 
Posts: 10
Joined: Mon Jul 21, 2014 4:39 pm

Wed Oct 11, 2017 1:33 am

Dear shaunlandau,

Thanks for your response.
Sorry that the solutions don't help you. After further investigation, we found the tags you used are not supported at present. We will continue to investigate the issue. Once there is any good news, we will inform you. One more thing, there are extra double quotation marks in your html, it would cause that the font color and underline are rendered incorrectly via browser.

Moreover, we found there is another solution, in which the underline and italics could work. Please use <u> and <i> tag, sample code for your reference:
Code: Select all
string htmlText= "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>. ";

If there is any question, please let us know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Oct 13, 2017 4:21 pm

The first quote character is an escape necessary when using the @ string feature in .NET (allows line breaks without tedious string concatenation) for strings that have quotes ... the resulting string has only one quote character. I tried exactly the example in documentation and it didn't work ... haven't tried your new suggestion but even if it does work it is not sufficient for my needs ... I need more robust HTML capability.

shaunlandau
 
Posts: 10
Joined: Mon Jul 21, 2014 4:39 pm

Mon Oct 16, 2017 1:44 am

Dear shaunlandau,

Thanks for your response.
So sorry that there was a mistake in the documentation, and we have changed the HTML code.
As for the previous HTML, we will look into it, and let you know if there is any progress.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF