Despite using the methods in this post…
[ Aspose.PDF for .NET Documentation|Aspose.PDF for .NET ]
…I’m still getting the [This document enabled extended features in Adobe Reader. The document has been changed since it was created and use of extended features is no longer available. Please contact the author for the original version of this document] error message in Reader X.
Here is my code:
private FileInfo BuildPdfTemplateFile(int ProjectReviewRequestID, DataTable dt, bool editable)
{
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(HttpContext.Current.Server.MapPath("~/App_References/Aspose.Total.lic"));
DataRow dr = dt.Rows[0];
string templateFilePath = HttpContext.Current.Server.MapPath("~/Forms/ProjectReview/ProjectReview_A.pdf");
FileInfo newPDF = new FileInfo(Path.GetTempFileName());
File.Copy(templateFilePath, newPDF.ToString(), true);
File.SetAttributes(newPDF.FullName, FileAttributes.Normal);
FileStream fs = new FileStream(newPDF.ToString(), FileMode.Open, FileAccess.ReadWrite);
Aspose.Pdf.Document templateFile = new Aspose.Pdf.Document(fs);
Aspose.Pdf.Facades.Form newForm = new Aspose.Pdf.Facades.Form(templateFile);
string SubmitButtonName = “”;
string SubmitLabelName = “”;
foreach (DataColumn dc in dt.Columns)
{
foreach (string fieldName in newForm.FieldNames)
{
if (fieldName.Contains(dc.ColumnName))
{
if (dc.ColumnName.StartsWith(“OWVals”))
{ }
switch (dc.ColumnName)
{
case “StartDate”:
case “EndDate”:
case “DeliveryDate”:
if (!string.IsNullOrEmpty(dr[dc.ColumnName].ToString()))
newForm.FillField(fieldName, Convert.ToDateTime(dr[dc.ColumnName].ToString()).ToString(“d MMM yyyy”));
break;
default:
if (!string.IsNullOrEmpty(dr[dc.ColumnName].ToString()) && IsDataColumnNumeric(dc))
{
if (dc.ColumnName.ToString().StartsWith(“OWVal”))
if (fieldName.Contains(".#field[" + dr[dc.ColumnName].ToString() + “]”))
{
string indexString = “#field[” + dr[dc.ColumnName].ToString() + “]”;
newForm.FillField(fieldName.Replace(indexString, “”), dr[dc.ColumnName].ToString());
}
if (dc.ColumnName.ToString().StartsWith(“Skills”))
if (fieldName.Contains(".#field[" + dr[dc.ColumnName].ToString() + “]”))
{
string indexString = “#field[” + dr[dc.ColumnName].ToString() + “]”;
newForm.FillField(fieldName.Replace(indexString, “”), dr[dc.ColumnName].ToString());
}
if (!dc.ColumnName.ToString().StartsWith(“OWVal”) && !dc.ColumnName.ToString().StartsWith(“Skills”))
newForm.FillField(fieldName, dr[dc.ColumnName].ToString());
}
else if (dr[dc.ColumnName].ToString().StartsWith("<body xfa"))
{
//RichTextBoxField rtfField = (RichTextBoxField) templateFile.Form[fieldName];
//rtfField.RValue = dr[dc.ColumnName].ToString();
templateFile.Form.XFA[fieldName] = dr[dc.ColumnName].ToString();
}
else
newForm.FillField(fieldName, dr[dc.ColumnName].ToString());
break;
}
}
if (fieldName.Contains(“EmailSubmitButton”))
{
SubmitButtonName = fieldName;
}
if (fieldName.Contains(“EmailSubmitLabel”))
{
SubmitLabelName = fieldName;
}
}
}
if (!editable)
{
newForm.FlattenField(SubmitButtonName);
}
templateFile.Save();
newForm.Save(fs);
fs.Close();
return newPDF;
}
Any thoughts?