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.

Thu Sep 12, 2019 5:33 am

Hello team.

Could you please help me in inserting HTML styled text to the PDF file in an existing page of the PDF?

The example given in your website (How to Insert HTML Styled Text to PDF in C#, VB.NET) helps only in inserting the HTML text to NEW page only.

Thanks in advance

monishkumar
 
Posts: 2
Joined: Thu Sep 12, 2019 5:27 am

Thu Sep 12, 2019 7:59 am

Hi,

Thanks for your inquiry.
At present the HTML text could only be drawn on PdfNewPage. But there is a way to achieve the same effect like drawing on existing page. Please refer to following code:
Code: Select all
            string text = "<p>Hello World</p>";
            PdfDocument doc = new PdfDocument(FilePath + "3page.pdf");
            //get the existing page which you want to insert HTML
            PdfPageBase originalPage = doc.Pages[0];
            //insert a PdfNewPage
            PdfNewPage page = doc.Pages.Insert(0, originalPage.Size) as PdfNewPage;
            //Draw the original content on new page
            page.Canvas.DrawTemplate(originalPage.CreateTemplate(), new PointF(0, 0));
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
            PdfBrush brush = PdfBrushes.Black;
            PdfHTMLTextElement HtmlContent = new PdfHTMLTextElement(text, font, brush);
            HtmlContent.TextAlign = Spire.Pdf.Graphics.TextAlign.Left;
            PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
            format.Layout = PdfLayoutType.Paginate;
            format.Break = PdfLayoutBreakType.FitPage;
            //draw html on the page
            HtmlContent.Draw(page, new RectangleF(20, 300, 200, 400), format);
            //remove original page
            doc.Pages.Remove(originalPage);         
            doc.SaveToFile("18885.pdf");

Any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Tue Oct 29, 2019 6:01 am

Hi,

Greetings from E-iceblue.
Is the code I provided helpful for you? Has your issue been resolved?

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Tue Nov 30, 2021 1:29 pm

PdfHTMLTextElement it not supported

dhanashri
 
Posts: 4
Joined: Tue Nov 30, 2021 1:18 pm

Wed Dec 01, 2021 1:18 am

Hello,

Thanks for your inquiry!

Do you mean that the “PdfHTMLTextElement” class does not exist in the Spire.PDF for Java? Kindly note that this class only exists in the Spire.PDF for .NET now, once it is supported in the Java version, I will inform you ASAP.

Sincerely,
Marcia
E-iceblue support team
User avatar

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

Wed Dec 01, 2021 9:01 am

PdfHTMLTextElement is not support in .net core 2.2

dhanashri
 
Posts: 4
Joined: Tue Nov 30, 2021 1:18 pm

Wed Dec 01, 2021 9:30 am

Hello,

Sorry that our Spire.PDF for net core does not include the "PdfHTMLTextElement" class. What kind of operation do you want to achieve through this class? Please describe your needs in detail, and I will try my best to help you find if there is another method.

Sincerely,
Marcia
E-iceblue support team
User avatar

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

Wed Dec 01, 2021 9:45 am

I want to find any string and replace string with html style text to pdf in .net core 2.2

dhanashri
 
Posts: 4
Joined: Tue Nov 30, 2021 1:18 pm

Wed Dec 01, 2021 10:04 am

Hello Support Team,

any news on this topic?

dhanashri
 
Posts: 4
Joined: Tue Nov 30, 2021 1:18 pm

Wed Dec 01, 2021 10:09 am

Hello,

Sorry that our Spire.PDF cannot achieve your needs. If you encounter any issues related to our product in the future, just feel free to contact us.

Sincerely,
Marcia
E-iceblue support team
User avatar

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

Return to Spire.PDF

cron