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.

Fri Mar 20, 2020 12:48 pm

How to create html table with form controls using spire pdf? Please help me on this. I am just planning to buy your product. I am using a trial version. But I am facing some difficulties.

my code is

string HtmlText ="";
HtmlText += "<br/><br/>Sincerely,";
HtmlText += "<br/><br/><br/>Testing Services<br/>123325256<br/><a style='color: black;' href='www.google.com'>www.google.com</a>";
HtmlText += "<br/><br/><table align='center' border='1'><tr><td>Test</td>"+
"<td><input type='text' id='fname' name='fname' value='testusha'/></td>" +
"</tr></table></form>";



richTextElement = new PdfHTMLTextElement(HtmlText, Contentfont, Contentbrush);

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

richTextElement.Draw(pageNew, new RectangleF(0, 140, pageNew.GetClientSize().Width, pageNew.GetClientSize().Height*10),format);

ushanandhini_1297
 
Posts: 15
Joined: Mon Apr 20, 2015 11:34 am

Mon Mar 23, 2020 7:53 am

Hello,

Thanks for your inquiry and sorry for the late reply as weekend.
I directly ran your code and got the XmlException error message, did you encounter the same issue?
After investigation, I found that the HtmlText you used missed a <form> tag, this would cause errors when parsing Tags. And after adding the missing tag, the code could work well. Below is the code I used, and I also attached my output file for your reference.
Code: Select all
            //Create a Pdf document
            PdfDocument doc = new PdfDocument();
            //Add a new page
            PdfNewPage pageNew = doc.Pages.Add() as PdfNewPage;
            string HtmlText = "";
            HtmlText += "<br/><br/>Sincerely,";
            HtmlText += "<br/><br/><br/>Testing Services<br/>123325256<br/><a style='color: black;' href='www.google.com'>www.google.com</a>";
            HtmlText += "<br/><br/><form><table align='center' border='1'><tr><td>Test</td>" +
            "<td><input type='text' id='fname' name='fname' value='testusha'/></td>" +
            "</tr></table></form>";

            //Render HTML text
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 15);
            PdfBrush brush = PdfBrushes.Black;
            PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(HtmlText, font, brush);

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

            richTextElement.Draw(pageNew, new RectangleF(0, 140, pageNew.GetClientSize().Width, pageNew.GetClientSize().Height * 10), format);
            doc.SaveToFile("Output.pdf");


Unfortunately, at present our Spire.PDF doesn't support form elements. You can see that the input tags are not rendered in my output document. However, we are considering adding it as new feature into our upgrade list with the ticket SPIREPDF-3133. If it can be achieved in the future, we will let you know.
Sorry for the inconvenience caused.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF