I am merging a set of documents into one that contain form fields that I am converting to labels.
How can I delete the form fields from the final merged document?
Delete Form Fields
Re: Delete Form Fields
Support · Aug 15, 2007Hello,
You can remove all the form fields from the final PDF document by setting the MergeOptions objects FormFields property to false when merging all PDFs.
Thanks,
ceTe Software Support Team
Re: Delete Form Fields
Forum member · Aug 15, 2007Still not working for me. Here is a code snippit.
When the interpreter gets to "this.flatPDF = new MergeDocument(completePDF, mo);" it throws an error "Index was outside the bounds of the array." If I remove the mo parameter, it works fine.
Greg
public MergeDocument FlatPDF()
{
// Draw the compiled PDF to a new PDFDocument
PdfDocument completePDF = new PdfDocument(this.ApplicationPDF.Draw());
// Create a new MergeDocument from the newly created flat PDF
MergeOptions mo = new MergeOptions(false);
this.flatPDF = new MergeDocument(completePDF, mo);
// Loop through all of the flat PDF fields and make them text areas
for (int i = 0; i < completePDF.Form.Fields.Count; i++)
{
this.FlatPDFAddFields(buildType, completePDF, completePDF.Form.Fields[i]);
}
return flatPDF;
}
private void FlatPDFAddFields(PdfDocument completePDF, PdfFormField parentField)
{
PdfFormFieldList fields = parentField.ChildFields;
ceTe.DynamicPDF.Color textColor = null;
ceTe.DynamicPDF.Font textFont = null;
ceTe.DynamicPDF.Font normalFont = ceTe.DynamicPDF.Font.TimesBold;
ceTe.DynamicPDF.TextAlign textAlign = TextAlign.Left;
float defaultTextSize = 10F;
float textSize = defaultTextSize;
float X = 0F;
float Y = 0F;
String text = "";
ceTe.DynamicPDF.Text.TrueTypeFont scriptFont = new ceTe.DynamicPDF.Text.TrueTypeFont(ConfigurationManager.AppSettings["PDFTemplates"] + @"/Fonts/LearningCurve.ttf");
ceTe.DynamicPDF.Text.TrueTypeFont checkFont = new ceTe.DynamicPDF.Text.TrueTypeFont(ConfigurationManager.AppSettings["PDFTemplates"] + @"/Fonts/DISTROBT.ttf");
for (int i = 0; i < fields.Count; i++)
{
PdfFormField field = parentField.ChildFields[i];
if (field is PdfTextField)
{
Int32 originalPageNumber = field.GetOriginalPageNumber();
if (originalPageNumber > 0)
{
Page page = flatPDF.Pages[originalPageNumber - 1];
X = field.GetX(page);
Y = field.GetY(page);
text = (parentField is PdfTextField) ? parentField.GetValue() : field.GetValue();
textAlign = TextAlign.Left;
PDFFieldFont fieldFont = this.fieldFonts.Find(delegate(PDFFieldFont f) { return (f.FieldName.Equals(field.Name)); });
textColor = ceTe.DynamicPDF.RgbColor.Green;
textFont = normalFont;
textSize = fieldFont != null && fieldFont.FontSize.HasValue ? fieldFont.FontSize.Value : defaultTextSize;
if (field.FullName.EndsWith("_Yes") || field.FullName.EndsWith("_No") || field.FullName.Contains("_Yes.") || field.FullName.Contains("_No."))
{
text = text.Equals("X") ? "|" : "";
textFont = checkFont;
textAlign = TextAlign.Center;
textSize = 11.25F;
}
TextArea textArea = new TextArea(text, X, Y, field.Width, field.Height, textFont, textSize, textAlign, textColor);
page.Elements.Add(textArea);
field.PositionPageElement(textArea, page);
}
}
if (field.HasChildFields)
this.FlatPDFAddFields(completePDF, field);
}
}
Re: Delete Form Fields
Support · Aug 15, 2007Hello Greg,
Can you please try replacing the following line of code "MergeOptions mo = new MergeOptions(false);" with
MergeOptions mo = new MergeOptions(true);
mo.FormFields = false;
Let us know if that solved the problem. If not, please send over the PDF files you are merging to our [^a|mailto:support@cete.com|Support Team^] so that we can take a look at it. Also doesthis.ApplicationPDF.Draw() you are merging have form fields?
Thanks,
ceTe Software Support Team