Merge two mergedocuments into single documetn

Merge two mergedocuments into single documetn

Forum member · Mar 4, 2009
I have created two mergedocuments that I would like to combine into a single PDF for output. I needed to use the mergedocuments to access form fields but I can't figure out how to merge them into a single document. Any ideas?

Re: Merge two mergedocuments into single documetn

Support · Mar 4, 2009
Hello, You can merge multiple PDF documents together and it will preserve the form fields on them. Following is the sample code to use: MergeDocument document = new MergeDocument(); document.Append(flename1); document.Append(flename2); document.DrawToWeb("Output.pdf"); The output PDF will have form fields from both original PDF templates and you can also do form filling. Thanks, ceTe Software Support Team

Re: Merge two mergedocuments into single documetn

Forum member · Mar 4, 2009
I need to have the documents separate when filling in the form and then merge the two final mergedocuments together. Is this possible? Sample Code: // If this is an adult if (Int32.Parse(row["Age"].ToString()) >= 18) { // Insert cover page if this is the first use of the adult cover page if (adultCoverPageFirstUse) { m_AdultPDF.Append(m_AdultCoverPageDocumentPath); adultCoverPageFirstUse = false; } m_AdultPDF.Append(m_AdultTemplate, new MergeOptions(true, adultIndexer.ToString())); m_AdultPDF.Form.Fields[adultIndexer.ToString() + ".txtDate"].Value = DateTime.Now.ToString("MM/dd/yyyy"); m_AdultPDF.Form.Fields[adultIndexer.ToString() + ".txtName"].Value = row["FullName"].ToString(); m_AdultPDF.Form.Fields[adultIndexer.ToString() + ".txtStreetAddress"].Value = row["Address1"].ToString(); m_AdultPDF.Form.Fields[adultIndexer.ToString() + ".txtCityStateZip"].Value = row["City"].ToString() + ", " + row["State"].ToString() + " " + row["ZipCode"].ToString(); m_AdultPDF.Form.Fields[adultIndexer.ToString() + ".txtName2"].Value = row["FullName"].ToString() + ":"; adultIndexer++; } // If this is a child else { // Insert cover page if this is the first use of the child cover page if (childCoverPageFirstUse) { m_ChildPDF.Append(m_ChildCoverPageDocumentPath); childCoverPageFirstUse = false; } m_ChildPDF.Append(m_ChildTemplate, new MergeOptions(true, childIndexer.ToString())); m_ChildPDF.Form.Fields[childIndexer.ToString() + ".txtDate"].Value = DateTime.Now.ToString("MM/dd/yyyy"); m_ChildPDF.Form.Fields[childIndexer.ToString() + ".txtName"].Value = row["FullName"].ToString() + " C/O Parent or Guardian"; m_ChildPDF.Form.Fields[childIndexer.ToString() + ".txtStreetAddress"].Value = row["Address1"].ToString(); m_ChildPDF.Form.Fields[childIndexer.ToString() + ".txtCityStateZip"].Value = row["City"].ToString() + ", " + row["State"].ToString() + " " + row["ZipCode"].ToString(); childIndexer++; }

Re: Merge two mergedocuments into single documetn

Support · Mar 5, 2009
Hello, You can fill the PDF documents separately and merge them into single PDF document using our DynamicPDF Merger product without any problem. Below is the sample code for it. //To fill the firsrt pdf document............ MergeDocument doc = new MergeDocument(@"Input1.pdf"); doc.Form.Fields["field name"].Value = "Hello 1"; byte[] byteData1 = doc.Draw(); //To fill the Second pdf document........ MergeDocument doc1 = new MergeDocument(@"Input2.pdf"); doc1.Form.Fields[""].Value = "Hello 2"; byte[] byteData2 = doc1.Draw(); //To merge the filled documents to make a single pdf document.... PdfDocument pdf1 = new PdfDocument(byteData1); PdfDocument pdf2 = new PdfDocument(byteData2); MergeDocument doc3 = new MergeDocument(pdf1); doc3.Append(pdf2); doc3.Draw(@"Output.pdf"); We however recommend that you merge the two PDF documents first and then perform form filling. Thanks, ceTe Software Support Team

Re: Merge two mergedocuments into single documetn

Forum member · Mar 5, 2009
Thank you for your response. I will try out your code shortly. I would like to ask why you recommend merging them first? Performance? Please let me know if I am going down the right path with respect to the project I am working on. Document 1 - Cover letter that will be sent to adults Document 2 - Cover letter that will be sent to children Each document is the same except for a header that has mailing addresses and some verbiage in the document itself. When I fill in the PDF's I insert the persons mailing address and then I add a new page for the next person etc. My process basically creates a stack of pages for mailing to individual people. If I merge both documents together how can I loop through all of my people records and create new adult or child pages? Example output: Stack 1 - 267 pages of adult letters Stack 2 - 482 pages of child letters Merged document would have 749 pages of letters with the first 267 for adults and the last 482 for children. Does this make sense?

Re: Merge two mergedocuments into single documetn

Forum member · Mar 5, 2009
Your solution worked perfectly for me! I very much appreciate your help with this. Also just so you know, there was no significant decrease in performance when I implemented your solution without merging the documents first. Thanks! Matt