See http://1t3xt.info/examples/browse/?page=example&id=35. The idea is to 
create the individual files with PdfStamper and then combine them with PdfCopy.

Paulo
  ----- Original Message ----- 
  From: John Polley 
  To: Post all your questions about iText here 
  Sent: Monday, April 05, 2010 9:12 PM
  Subject: Re: [iText-questions] Question about merging pdf documents


  Paulo,

   

  Thanks for the quick response. I’ve tried to find an example or some 
documentation as to what you mean but can’t come up with anything. Would you 
please tell me exactly how to reload the pdf written by the stamper. Also, I’d 
really like to be creating the stamper documents in memory… do I do this just 
by changing the os used when creating the stamper?

   

  Thanks again for your help!

   

  From: Paulo Soares [mailto:psoa...@glintt.com] 
  Sent: Monday, April 05, 2010 3:48 PM
  To: Post all your questions about iText here
  Subject: Re: [iText-questions] Question about merging pdf documents

   

  After closing stamper you'll have to reload the pdf written by stamper.

   

  Paulo

    ----- Original Message ----- 

    From: John Polley 

    To: itext-questions@lists.sourceforge.net 

    Sent: Monday, April 05, 2010 8:40 PM

    Subject: [iText-questions] Question about merging pdf documents

     

    Hi,

     

    I’ve been trying to get this to work for several days now and am pretty 
close but, it appears that I am overlooking something. I am writing a comclass 
using VS2005 and the itext class. The comclass reads from records from a 
database and then, using a pdf document with form fields, creates a separate 
page (i.e., document) for each record in the table. My comclass works just fine 
if I write each resulting pdf out to separate file but I’d like to merge the 
individual documents into a single pdf. Here is the code that I am using:

     

    Dim out As New System.IO.FileStream(Me._CreateDocumentPath & 
Me._CreateDocumentName, FileMode.Create)

            Dim document As New Document()

            Dim writer As PdfWriter = PdfWriter.GetInstance(document, out)

            document.Open()

            Dim page As PdfImportedPage

            Dim fieldvalue As String = ""

            Using connection As SqlConnection = New 
SqlConnection(builder.ConnectionString)

                Try

                    connection.Open()

                Catch exception1 As SqlException

                    ProjectData.SetProjectError(exception1)

                    Dim exception As SqlException = exception1

                    
Interaction.MsgBox((Conversions.ToString(exception.ErrorCode) & " " & 
exception.Message), MsgBoxStyle.OkOnly, Nothing)

                    Dim str3 As String = ("Error: on database connection: " & 
Conversions.ToString(exception.ErrorCode) & " " & exception.Message)

                    ProjectData.ClearProjectError()

                    Return str3

                End Try

                Using command As SqlCommand = New SqlCommand("SELECT * FROM 
##PDFFormValues", connection)

                    Using reader2 As SqlDataReader = command.ExecuteReader

                        Dim pagecount As Integer = 1

                        Dim fieldCount As Integer = reader2.FieldCount

                        Dim num3 As Integer = (fieldCount - 1)                

                        Do While reader2.Read

                            Dim reader As New PdfReader(filename)

                            Dim stamper As New PdfStamper(reader, New 
FileStream("h:\temp" & pagecount & ".pdf", FileMode.Create))   ' New 
FileStream(path, FileMode.Create))

                            Dim acroFields As AcroFields = stamper.AcroFields

                            Dim i As Integer = 0

                            Do While (i <= num3)

                                If IsDBNull(reader2.GetValue(i)) Then

                                    fieldvalue = ""

                                Else

                                    fieldvalue = reader2.GetValue(i)

                                End If

                                acroFields.SetField(reader2.GetName(i), 
Conversions.ToString(fieldvalue))

                                i += 1

                            Loop

                            stamper.FormFlattening = True

                            stamper.Close()

                            page = writer.GetImportedPage(reader, 1)    'This 
gives blank forms if stamper.close is commented out, otherwise, i get error 14

                            document.NewPage()

                            writer.DirectContent.AddTemplate(page, 0, 0)

                            pagecount += 1

                        Loop

                        reader2.Close()

                    End Using

                End Using

            End Using

     

    The closest that I have gotten is a document with the correct number of 
pages (ie. One for each record in my table) but with none of the form fields 
showing.

     

    I’d really appreciate it if you could point out what I have done wrong or 
an missing.

     

    Regards.
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to