Hi Guys
Any feedback?
Hi Garreth,
Thanks for contacting support.
In order to accomplish your requirements, please try using following code snippet.
[.NET]
// Create an instance of FormEditor class and bind input PDF file
Aspose.Pdf.Facades.FormEditor editor = new Aspose.Pdf.Facades.FormEditor();
editor.BindPdf(doc);
// Add a submit button and set target URL
editor.AddSubmitBtn("submitbutton", 1, "Submit", "http://localhost/csharptesting/show.aspx", 100, 450, 150, 475);
// Save output PDF file
editor.Save("c:/pdftest/SubmitButton.pdf");
Why are we binding two documents?
Also the suggested method you have shown will not working with converting html file to pdf as far as i can see. This method would need the pdf file generated from scratch ?
My code sample below:
public static string GenerateHTMLForm()
{
string strDataDir = GetDataDir();
StringBuilder strHTML = new StringBuilder();
// Start generating the HTML content
using (var db = new Entities())
{
Cars car = db.Cars.Find(CarsId);
strHTML.Append($"<h1>{car.DisplayName}</h1>");
// CSS styles
strHTML.Append("<style>");
strHTML.Append("body { font-family: Arial; font-size: 12px; margin: 0px; padding: 0px; } ");
strHTML.Append(".txtBox { width: 99%; height: 22px; outline: none; border: none; border: 1px solid #ccc !important; padding: 3px; }");
strHTML.Append("</style>");
// Counter for fields
int iCount = 0;
// Iterate through fields from the database
foreach (var item in db.GetFields.Where(m => m.IsActive == true).OrderBy(x => x.QuestionSequence).ToList())
{
iCount++;
// Label for the field
strHTML.Append("<div>");
strHTML.Append($"<label>{iCount}. {item.FieldName}</label>");
strHTML.Append("</div>");
// Determine field type (e.g., text box, dropdown, etc.)
strHTML.Append("<div>");
if (item.FieldType == "textbox")
{
strHTML.Append($"<input type='text' class='txtBox' id='{item.FieldId}' name='{item.FieldName}' />");
}
else if (item.FieldType == "dropdown")
{
// Example dropdown
strHTML.Append("<select>");
strHTML.Append("<option value='value1'>Option 1</option>");
strHTML.Append("<option value='value2'>Option 2</option>");
strHTML.Append("</select>");
}
strHTML.Append("</div>");
// Blank row for spacing
strHTML.Append("<div> </div>");
}
}
// Write the HTML content to a file
File.WriteAllText(strDataDir + "myfile.htm", strHTML.ToString());
return strDataDir;
}
Please can we get some feedback here - a day between each comment is not really going to suffice. We have bought the licence and would require some support in this matter.
No feedback still
Hi Garreth,
Thanks for sharing the details and sorry for the delayed response.
In earlier shared code snippet, an existing PDF file is loaded. However in order to load an HTML file and save it to PDF format with Submit button, please try using following code snippet. For your reference, I have also attached the output generated over my end.
[C#]
//### Generate the html file
StringBuilder strHTML = new StringBuilder();
strHTML.Append("<h1>" + "Survey.DisplayName" + "</h1>");
//### Css styles
strHTML.Append("<style>");
strHTML.Append("body { font-family: Arial; font-size: 12px; margin: 0px; padding: 0px; } ");
strHTML.Append(".txtBox { width: 99%; height: 22px; outline: none; border: none; border: 1px solid #ccc !important; padding: 3px; }");
strHTML.Append("</style>");
strHTML.Append("<div>");
strHTML.Append("<label>1. " + "item.FieldName" + "</label>");
strHTML.Append("</div>");
strHTML.Append("<div>");
strHTML.Append("<input type='text' class='txtBox' id='FieldId' name='FieldName' />");
strHTML.Append("</div>");
strHTML.Append("<div> </div>");
strHTML.Append("<div>");
strHTML.Append("<input type='submit' id='submitbutton' value='Submit' formaction='http://localhost/csharptesting/show.aspx' style='position:absolute;left:100px;top:450px;width:150px;height:25px;' />");
strHTML.Append("</div>");
File.WriteAllText("c:/pdftest/myfile.htm", strHTML.ToString());
// Load HTML file into Aspose.Pdf.Document
Document doc = new Document("c:/pdftest/myfile.htm", new HtmlLoadOptions());
// Save HTML as PDF
doc.Save("c:/pdftest/myfile.pdf");
// Create an instance of FormEditor class and bind input and output PDF files
Aspose.Pdf.Facades.FormEditor editor = new Aspose.Pdf.Facades.FormEditor();
editor.BindPdf(doc);
// Add a submit button and set target URL
editor.AddSubmitBtn("submitbutton", 1, "Submit", "http://localhost/csharptesting/show.aspx", 100, 450, 150, 475);
// Save output PDF file with submit button
editor.Save("c:/pdftest/SubmitButton.pdf");