Add a new page from existing page

Add a new page from existing page

Forum member · May 4, 2007
Hi, I am trying to create continuation sheets from existing pages. The original document has 5 pages. The pdf document has multiple form fields which will eventually be filled up. I am using this code. ceTe.DynamicPDF.Merger.MergeDocument doc = new MergeDocument(@"C:\OriginalTemplate.pdf"); ImportedPage newPage = new ImportedPage(@"C:\OriginalTemplate.pdf", 5); newPage.ImportFormFields = true; doc.Pages.Add(newPage); doc.Draw(@"C:\MyForm.pdf"); Please help as the code fails with the following error. ceTe.DynamicPDF.GeneratorException was unhandled Message="Invalid page number." Source="ceTe.DynamicPDF.20" StackTrace: at zz93aa.e(Int32 A_0) at zz93gs.a(DocumentWriter A_0) at ceTe.DynamicPDF.Forms.FormField.Draw(DocumentWriter writer) at ceTe.DynamicPDF.IO.DocumentResourceList.a(DocumentWriter A_0) at zz93aa.v() at ceTe.DynamicPDF.Document.Draw(String filePath) at WindowsApplication2.Form1.simpleButton1_Click(Object sender, EventArgs e) in C:\Documents and Settings\basuk\My Documents\Visual Studio 2005\Projects\WindowsApplication2\WindowsApplication2\Form1.cs:line 149 at System.Windows.Forms.Control.OnClick(EventArgs e) at DevExpress.XtraEditors.BaseButton.OnClick(EventArgs e) at DevExpress.XtraEditors.BaseButton.OnMouseUp(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at WindowsApplication2.Program.Main() in C:\Documents and Settings\basuk\My Documents\Visual Studio 2005\Projects\WindowsApplication2\WindowsApplication2\Program.cs:line 16 at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() However if I use doc.Pages.Insert(newPage, 3) it works, but if I use doc.Pages.Insert(newPage, 4) it fails with the same error.

Re: Add a new page from existing page

Support · May 4, 2007
Hello, When merging the PDF, the form fields from the existing PDF document will be preserved by default. If you want to merge the same PDF document multiple times, you can use the Append method. MergeDocument document = new MergeDocument(@"C:\OriginalTemplate.pdf"); document.Append(@"C:\OriginalTemplate.pdf", 5); document.DrawToWeb("Test.pdf"); Yes, you can merge same PDF form multiple times without any problem and fill them with different data from the database. You can use the PdfDocument object for the PDF template and an empty MergeDocument object to start with. Then using the overloaded Append method of the MergeDocument object append the PDF multiple times. It is possible to reorganize the Acro Form fields as they are merged into the PDF document several times. This prevents renaming issues and helps better organize the form field data. Following is the link to the Help Documentation on the web site that shows how to prevent renaming of form fields using MergeOptions. Look at the "Filling Reorganized Acro Form Fields" at the bottom. Thanks, ceTe Software Support Team