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 Sep 06, 2022 4:12 pm

Hi ,

1. I am trying to write a hyperlink text using <a> href in a pdf file. But the hyperlink content is plain text and not a hyperlink clickable one.
2. Also the html <p> tag is not converting to a paragraph in pdf.

Could anyone please provide some guidance on this?

Code: Select all

PdfDocument doc = new PdfDocument();
byte[] pdf = File.ReadAllBytes(@"C:/test.pdf");
doc.LoadFromBytes(pdf);
PdfPageBase page = doc.Pages[0];

 PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Verdana", 12, System.Drawing.FontStyle.Bold));
               String url1 = "<p>We have a dual licensing business model. " +
                "You can use the SDK at no cost if you open source the application you are integrating the iText SDK into per" +
                " the terms of the AGPL license, or you can license iText commercially if you don’t want to open source your entire" +
                " application.</p><p>This demo shows how we can insert <a href='https://www.w3schools.com'>Visit W3Schools</a>" +
                " <u><i>HTML styled text</i></u> to PDF using "
                + "<font color='#FF4500'>Spire.PDF for .NET</font>.</p>";

//Option 1
            PdfHTMLTextElement HtmlContent = new PdfHTMLTextElement(url1, font2, PdfBrushes.Black);
            HtmlContent.TextAlign = TextAlign.Justify;
            HtmlContent.Draw(page.Canvas, new RectangleF(20, 300, 200, 400));

//Option 2

            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 5);
            PdfBrush brush = PdfBrushes.Black;
            PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(url1, font, brush);
            richTextElement.TextAlign = TextAlign.Left;
            richTextElement.Draw(page.Canvas, new RectangleF(0, 20, page.GetClientSize().Width, page.GetClientSize().Height / 2));

doc.SaveToFile(@"C:\Output.pdf");




Thanks
Chitra

chitraotech_123
 
Posts: 3
Joined: Tue Sep 06, 2022 3:43 pm

Wed Sep 07, 2022 9:59 am

Hi,

Thank you for your inquiry.
I reproduced your problem and logged it into our bug tracking system with ticket SPIREPDF-5471. Our dev team will investigate this issue, once there is any good news, I will inform you. Apologize for the inconvenience.

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Return to Spire.PDF