Hello,
I have created a PDF using Aspose.Pdf.Generator with HTML data embedded (see attached). But the elements within the pdf are editable. Scrollbars also appear within the textbox.
Please let me know how to make the PDF non-editable. The data should look as text and not as an inline textbox.
Thanks,
Viswanathan
Hi Viswanathan,
I think you can get your desired result by creating a PDF file using Aspose.Pdf.Generator, saving it to a memory stream and opening it with Aspose.Pdf.Facades and flattening the form fields. Please see the following sample code in this regard:
// Instantiate an object PDF class
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
// add the section to PDF document sections collection
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
// Read the contents of HTML file into StreamReader object
StreamReader r = File.OpenText(@"D:\Source_Files\myHtml.html");
//Create text paragraphs containing HTML text
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());
// enable the property to display HTML contents within their own formatting
text2.IsHtmlTagSupported = true;
//Add the text paragraphs containing HTML text to the section
section.Paragraphs.Add(text2);
// Specify the URL which serves as images database
pdf.HtmlInfo.ImgUrl = @"D:\Source_Files\";
// Save PDF to a MemoryStream
MemoryStream tempMemoryStream = new MemoryStream();
pdf.Save(tempMemoryStream);
//open document
Aspose.Pdf.Facades.Form pdfForm = new Aspose.Pdf.Facades.Form(tempMemoryStream, @"D:\ Source_Files\myHtml.pdf");
//flatten fields
pdfForm.FlattenAllFields();
//save output
pdfForm.Save();
Please do let us know if the above solution fits your needs. If not, please provide us some more details with template HTML file and sample code to understand the issue/requirement.
Thank You & Best Regards,
Lovely! that solves my issue.
Thanks!
Vish