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