new PdfHTMLTextElement and Line Breaks

Technical support for Spire.PDF

Moderator: iceblue support

new PdfHTMLTextElement and Line Breaks

Postby rambach » Mon Jun 26, 2017 2:49 pm

I'm using the following code in C#:

The "txtContent.Text" is a CKEditor richtext box. Spire.PDF is able to read the textbox but the format isn't what it looks like in the textbox. It doesn't add all the HTML elements like bullets and carriage returns. What am I doing wrong?

Code: Select all
PdfDocument Doc= new PdfDocument();
        PdfNewPage page = Doc.Pages.Add(PdfPageSize.Note) as PdfNewPage;

        PdfFont font = new PdfFont(PdfFontFamily.Helvetica,2,PdfFontStyle.Regular);
        PdfBrush brush = PdfBrushes.Black;

        PdfHTMLTextElement kbContent = new PdfHTMLTextElement(txtContent.Text, font, brush);

        kbContent.TextAlign = Spire.Pdf.Graphics.TextAlign.Left;

        PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
        format.Layout = PdfLayoutType.Paginate;
        format.Break = PdfLayoutBreakType.FitPage;

        kbContent.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);

Posts: 6
Joined: Thu Nov 17, 2016 5:55 pm

Re: new PdfHTMLTextElement and Line Breaks

Postby Betsy.jiang » Tue Jun 27, 2017 8:31 am

Dear rambach,

Thanks for your inquiry.
1)For the bullets tag, the PdfHTMLTextElement indeed doesn't recognize it now, and our Dev team is working on it. We will let you know once there is any great progress.
2)For the carriage returns <br/> tag, it could work. Please see below HTML worked on my side.
Code: Select all
String HTML = "hello <br/>world";

Moreover, there is a solution which you could choose. Please use Spire.Doc and then append the HTML, finally save the document as PDF, it could apply the bullet and carriage return tags successfully. Below is sample code for your kind reference.
Code: Select all
            string HTML = "<ul><li>Coffee</li><li>Tea</li><li>Milk</li></ul>hello <br/>world";
            Document doc = new Document();
            Section sec = doc.AddSection();
            Paragraph par = sec.AddParagraph();
            doc.SaveToFile("10943.pdf", FileFormat.PDF);

E-iceblue support team
User avatar
Posts: 1433
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF

Who is online

Users browsing this forum: No registered users and 0 guests