Hi.
I am using EO.Pdf for .NET (C#). Using the library, I have successfully been able to read and modify existing PDF form fields changing the
value of the field and setting the field to
read-only, however I need to
flatten it so when the PDF is saved it does not act as a field, but as normal
text. How would I do this?
The code I'm using is based on a simple Windows form application that holds the folder path in a text box and a button that has the following Click event.
Code: C#
private void button1_Click(object sender, EventArgs e)
{
try
{
var folderpath = string.Format(@"{0}", textBoxFolder.Text);
var sourcePdfName = "sample1.pdf";
var targetPdfName = "demo1.pdf";
var sourceFilename = string.Format("{0}{1}", folderpath, sourcePdfName);
var targetFilename = string.Format("{0}{1}", folderpath, targetPdfName);
var doc = new PdfDocument(sourceFilename);
var fields = doc.Fields;
var sb = new StringBuilder();
sb.AppendLine("The following fields have been identified in the PDF document:");
foreach (var field in fields)
{
sb.AppendLine(string.Format("Field Name: {0}", field.Name));
//NameAddress
//CustomerName
//AccountNo
if (field.Name == "AccountNo")
{
field.Value = "####-####-####-4587";
field.ReadOnly = true;
// TODO: work out how to flatten the field so it appears like normal text when saved. Leave other fields enabled.
}
}
sb.AppendLine();
sb.AppendLine(string.Format("New PDF created: {0}", targetPdfName));
doc.Save(targetFilename);
textboxOutputResults.Text = sb.ToString();
}
catch (Exception exception)
{
textboxOutputResults.Text = exception.Message;
}
}
I would appreciate any suggestions.
Thanks :)