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.

Tue Jun 11, 2024 5:37 pm

Hello.
I've some HTML to print inside a PDF.
Basic example:
<TABLE>
<TR><TD>Row 1 Col 1</TD><TD>Row 1 Col 2</TD></TR>
<TR><TD>Row 2 Col 1</TD><TD>Row 2 Col 2</TD></TR>
</TABLE>

I've tried drawString with htmlTags true but it throw an exception.
Does it exists a way to do it?
Otherwise what can I do to draw this HTML inside a PDF in a rectangle?
Thanks,
Mirko

mirko.golfieri
 
Posts: 15
Joined: Wed Jan 24, 2024 4:43 pm

Wed Jun 12, 2024 1:54 am

Hello,

Thanks for your inquiry.
Please refer to the following code to draw the HtmlString in Pdf. If you have any other questions, please feel free to write back.
Code: Select all
PdfDocument doc = new PdfDocument();

//Add a new page
PdfNewPage page = doc.Pages.Add() as PdfNewPage;

//HTML string
string htmlText = "<TABLE>\r\n<TR><TD>Row 1 Col 1</TD><TD>Row 1 Col 2</TD></TR>\r\n<TR><TD>Row 2 Col 1</TD><TD>Row 2 Col 2</TD></TR>\r\n</TABLE>";

//Render HTML text
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 25);
PdfBrush brush = PdfBrushes.Black;
PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(htmlText, font, brush);
richTextElement.TextAlign = TextAlign.Left;

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

//Draw htmlString 
richTextElement.Draw(page, new RectangleF(0, 20, page.GetClientSize().Width, page.GetClientSize().Height), format);


String result = "InsertSimpleHTMLString-result.pdf";
doc.SaveToFile(result);

Sincerely
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Fri Jun 14, 2024 8:53 am

Hello,
I do not find PdfHTMLTextElement in Java library.

Mirko

mirko.golfieri
 
Posts: 15
Joined: Wed Jan 24, 2024 4:43 pm

Fri Jun 14, 2024 9:13 am

Hello,

Thanks for your reply.
Sorry, currently our Spire.PDF for Java does not support inserting HtmlString in pdf files. We have added this to our update list with the ticket SPIREPDF-6834. Our dev team will further implement it. I will inform you in time after it is implemented.

Sincerely
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Fri Jun 14, 2024 9:17 am

Ops.
Do you have any idea regards the delivery date?

Thanks a lot,
Mirko

mirko.golfieri
 
Posts: 15
Joined: Wed Jan 24, 2024 4:43 pm

Mon Jun 17, 2024 1:29 am

Hello,

Thanks for your reply.
Sorry, we cannot provide a delivery date at the moment. It depends on the priority of your issue and the processing speed of dev team. Once there is any progress, we will inform you as soon as possible. Thank you for your understanding.

Sincerely
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.PDF

cron