Hello,
I have a process that will create an 1800+ page mergedocument. Each page of the merge document will use a standard template (like a letter) that I will add an address and name to. Similar to the following: Anything in [] is something I will add on each page. The letter is a single page also.
[Date]
[Name]
[Address]
[City, State, Zip]
Dear [Name],
<paragraph of text here>
My template pdf has form fields for each of the [] areas above. I was able to get my utility to create the PDF document using mergedocuments but that used upwards of 2.5GB of memory... obviously not the most efficient way to do it. So now I can create it very quickly using a PdfDocument object for each page, however I can't seem to figure out how to access my form fields.
#1 Is it even possible, and
#2 if it is, how can I do this?
Here is my code I am using:
PdfDocument page = new PdfDocument(m_DocumentPath);
foreach (DataRow row in m_DataTable.Rows)
{
// Fill in the fields for this page
//page.Form.Fields["txtDate"].Value = DateTime.Now.ToString("MM/dd/yyyy");
//page.Form.Fields["txtName"].Value = row["FullName"].ToString();
//page.Form.Fields["txtStreetAddress"].Value = row["Address1"].ToString();
//page.Form.Fields["txtCityStateZip"].Value = row["City"].ToString() + ", " + row["State"].ToString() + " " + row["ZipCode"].ToString();
//page.Form.Fields["txtName2"].Value = row["FullName"].ToString();
// Append the introduction document
m_PDF.Append(page);
}
Thank you for your time!
Matt
ImportedPage and Form Fields - Advice Needed
Re: ImportedPage and Form Fields - Advice Needed
Support · Dec 4, 2008Hello Matt,
Using the PdfDocument object will be more efficient since it will load the PDF document template that is used multiple times only once in the memory. Then pass the PdfDocument object to the MergeDocument constructor and do the form filling. Following is the sample code:
PdfDocument page = new PdfDocument(m_DocumentPath);
MergeDocument document = new MergeDocument(page);
document. Form.Fields["txtDate"].Value = DateTime.Now.ToString("MM/dd/yyyy");
Thanks,
ceTe Software Support Team
Re: ImportedPage and Form Fields - Advice Needed
Forum member · Dec 4, 2008I understand how this can work, but how do I use it in a loop?
I need to fill in a form for over 1800 pages... Is there something similar to the following that I can use?
PdfDocument template = new PdfDocument(m_path);
MergeDocument m_PDF = new MergeDocument(template);
foreach (DataRow row in m_DataTable.Rows)
{
// This works
m_PDF.Form.Fields["txtName"].Value = "Test Name";
// This is what I'm looking for
------> m_PDF.Pages[counter].Form.Fields["TxtName"].Value = "Test name";
}
Is this possible?
Re: ImportedPage and Form Fields - Advice Needed
Support · Dec 4, 2008Hello,
It can be done by renaming the form fields and that will give you control over the field name if they occur multiple times in the PDF document. To have it work more efficiently, please merge the template as many number of times as required first before starting to do form filling. Below is the sample code block:
PdfDocument template = new PdfDocument(m_path);
MergeDocument m_PDF = new MergeDocument();
foreach (DataRow row in m_DataTable.Rows)
{
M_PDF.Append(template, new MergeOptions(True, "1")
// This works
m_PDF.Form.Fields["1.txtName"].Value = "Test Name";
}
By renaming the form fields and merging the entire PDF before starting to fill the form fields, you will not have to worry about the page number on which you currently are.
Thanks,
ceTe Software Support Team
Re: ImportedPage and Form Fields - Advice Needed
Forum member · Dec 4, 2008You see... this is why I absolutely love your product. There is always an efficient way to do things.
Thank you so much! Once again, your supports kicks butt!
Matt
Re: ImportedPage and Form Fields - Advice Needed
Forum member · Dec 4, 2008Just a quick FYI, I had to use a counter to name the fields, i.e.
int counter = 0;
foreach (DataRow row in m_DataTable.Rows)
{
m_PDF.Append(m_Template, new MergeOptions(true, counter.ToString()));
m_PDF.Form.Fields[counter.ToString() + ".txtDate"].Value = DateTime.Now.ToString("MM/dd/yyyy");
m_PDF.Form.Fields[counter.ToString() + ".txtName"].Value = row["FullName"].ToString();
m_PDF.Form.Fields[counter.ToString() + ".txtStreetAddress"].Value = row["Address1"].ToString();
m_PDF.Form.Fields[counter.ToString() + ".txtCityStateZip"].Value = row["City"].ToString() + ", " + row["State"].ToString() + " " + row["ZipCode"].ToString();
m_PDF.Form.Fields[counter.ToString() + ".txtName2"].Value = row["FullName"].ToString() + ",";
counter++;
}