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 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);

       

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

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();
            par.AppendHTML(HTML);
            doc.SaveToFile("10943.pdf", FileFormat.PDF);


Sincerely,
Betsy
E-iceblue support team
User avatar

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

Return to Spire.PDF