Add To PDF

Add To PDF

Forum member · Aug 14, 2006
I have a template PDF with one textfield. What I'm trying to do is add the template PDF numerous times to itself (i.e. one PDF, 20 pages all the same) For I have it working in the sense that it adds the correct number of pages, but I can't seem to populate the textfield on each page with a different value. Any Ideas? Here's my code; Sub GenReport(ByVal compCode As Integer) Dim options As MergeOptions = New MergeOptions(True) Dim cookie As HttpCookie cookie = Request.Cookies("uName") Dim MyDocument As MergeDocument = New MergeDocument(MapPath(TemlatePath), options) MyDocument.Creator = "AJ" MyDocument.Author = "AJ" MyDocument.Title = "OUTPUT PDF" While rs.Read MyDocument.Form.Fields("TID").Value = rs("tID").ToString AddSelectedPagesFromDocument(MyDocument, MapPath(TemlatePath)) End While MyDocument.DrawToWeb(Me, "test.pdf") Response.End() End Sub Private Sub AddSelectedPagesFromDocument(ByVal MyDocument As Document, ByVal ImportDocument As String) Dim MyPdfDocument As PdfDocument = New PdfDocument(ImportDocument) MyDocument.Pages.Add(New ImportedPage(MyPdfDocument.GetPage(1))) End Sub

Re: Add To PDF

Support · Aug 15, 2006
Hello, Are all the text fields getting populated with the same value on each page or do the text fields come up blank? Can you please send the original PDF document you are using to merge several times to our [^a|mailto:support@cete.com|Support Team^], so that they will try to create the same behavior at their end? Thanks, ceTe Software Support Team

Re: Add To PDF

Forum member · Aug 15, 2006
I've sent my template pdf to your tech support. Another way to look at this is to create a blank document and add the pages one by one. The problem is the correct nubmer of pages are being added, but I get this error ++++++++++++++++++++++ Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. ++++++++++++++++++++++ when the docOUT.DrawToWeb is called. Here's my code. Dim cn As New SqlConnection(sConnect) cn.Open() Dim rs As SqlDataReader Dim cmd As New SqlCommand cmd.Connection = cn cmd.CommandType = CommandType.Text cmd.CommandText = sSql rs = cmd.ExecuteReader Dim options As MergeOptions = New MergeOptions(True) Dim cookie As HttpCookie cookie = Request.Cookies("uName") Dim MyDocument As MergeDocument = New MergeDocument(MapPath(TemlatePath), options) MyDocument.Creator = "AJ" MyDocument.Author = "AJ MyDocument.Title = "Template Doc" MyDocument.Form.Fields("TID").Value = "Aaron" Dim docOUT As Document = New Document While rs.Read MyDocument.Form.Fields("TID").Value = rs("tID").ToString docOUT.Pages.Add(MyDocument.Pages(0)) End While 'Response.Write(docOUT.Pages.Count) 'Response.End() docOUT.DrawToWeb(Me, "test.pdf") Response.End()

Re: Add To PDF

Support · Aug 15, 2006
Hello, The reason you are not able to fill the form fields and seeing the pages appended is because when adding pages using ImportedPage, it is only importing the page without preserving any form fields. So, when you try to reference the form field with its name, the NullPointerException gets raised because the form field is not found. Following is the sample code that will likely solve your problem: Dim MyPdfDocument As PdfDocument = New PdfDocument("C:\Temp\FFIEC1.pdf") Dim MyDocument As MergeDocument = New MergeDocument Dim I As Integer For I = 0 To 10 Dim options As MergeOptions = New MergeOptions(True, "pre" & I) MyDocument.Append(MyPdfDocument, options) MyDocument.Form.Fields("pre" & I & ".TID").Value = "Hello" & I Next MyDocument.DrawToWeb(Me, "test.pdf") Response.End() In the code above, the form fields are renamed by adding a prefix in order to have control over the renaming of the fields as the fields will get renamed by default if the same PDF document with form fields gets appending multiple times. Thanks, ceTe Software Support Team