referencing a formelement in a pagelist.page

referencing a formelement in a pagelist.page

Forum member · May 24, 2006
Hello, I am attempting to find which page within the pagelist contains a specific formfield. I can reference a list of formelements in the document.form.formfield object. But I can not reference a formelement within a page object of the pagelist. How can I reference a formelement within a page object?

Re: referencing a formelement in a pagelist.page

Support · May 25, 2006
Hello, In order to find out the page on which a particular form field exists, you can use the GetOriginalPageNumber() method of the PdfFormField class. Following is the sample code snippet: [Visual Basic] Dim MyPages as Page() = objDocument.Append( MyPdfDocument ) Dim MyF1_1 as PdfFormField = MyPdfDocument.Form.Fields( "f1-1" ) Dim MyF1_5 as PdfFormField = MyPdfDocument.Form.Fields( "f1-5" ) ' Add the labels MyF1_1.CreateLabel( MyPages( MyF1_1.GetOriginalPageNumber() - 1 ), "Acme Corp.", ceTe.DynamicPDF.Font.Courier, 12 ) MyF1_5.CreateLabel( MyPages( MyF1_5.GetOriginalPageNumber() - 1 ), "Anytown, DC 12345", ceTe.DynamicPDF.Font.Courier, 12 ) [C#] Page[] pages = document.Append( pdfDocument ); // Retrieve the form fields PdfFormField f1_1 = pdfDocument.Form.Fields[ "f1-1" ]; PdfFormField f1_5 = pdfDocument.Form.Fields[ "f1-5" ]; // Add the labels f1_1.CreateLabel( pages[f1_1.GetOriginalPageNumber() - 1], "Acme Corp.", ceTe.DynamicPDF.Font.Courier, 12 ); f1_5.CreateLabel( pages[f1_5.GetOriginalPageNumber() - 1], "Anytown, DC 12345", ceTe.DynamicPDF.Font.Courier, 12 ); Thanks, ceTe Software Support Team

Re: referencing a formelement in a pagelist.page

Forum member · May 25, 2006
Your example helps a lot. How can I cast a FormField to a PDFformField? I am attempting to get the page number where the field exists. Here is my working code. int targetPage = 0; // page var // if the form field exists if (parentDocument.Form.Fields[targetFieldName] != null) { // if the page element contains a textfield of the target name ceTe.DynamicPDF.Merger.Forms.PdfFormField targetFieldObj = parentDocument.Form.Fields[targetFieldName]; ceTe.DynamicPDF.Page basePage = parentDocument.Pages[targetFieldObj.GetOriginalPageNumber() - 1]; for(int i = 0; i <= parentDocument.Pages.Count; i++) { if (basePage.Equals(parentDocument.Pages[i])) { targetPage = i; } } // now validate the results if (targetPage > 0) { return targetPage; } else { // throw an error //return targetPage; throw new ApplicationException("Field not found! The field: " + targetFieldName + " in the document: " + parentDocument.Title + " was not found."); }

Re: referencing a formelement in a pagelist.page

Support · May 25, 2006
Hello, You cannot cast FormField to a PdfFormField class . In order to get the PdfFormField class you will need to initialize a PdfDocument object and then pass the PdfDocument object to your MergeDocument constructor. Following is sample code block which shows how to get access to the PdfFormField. // Input Document PdfDocument pdfDocument = new PdfDocument( @"C:\fw9_03_AcroForm.pdf" ); // Merged Document MergeDocument document = new MergeDocument(); // Append the input document and return a Pages array Page[] pages = document.Append( pdfDocument ); // Retrieve the form fields PdfFormField f1_1 = pdfDocument.Form.Fields[ "f1-1" ]; f1_1.CreateLabel( pages[f1_1.GetOriginalPageNumber() - 1], "Acme Corp.", ceTe.DynamicPDF.Font.Courier, 12 ); // Save the PDF document.Draw( @"C:\MyDoc.pdf" ); Thanks, ceTe Software Support Team