Spire PDF File Merge

Technical support for Spire.PDF

Moderator: iceblue support

Spire PDF File Merge

Postby grahamjg » Tue Jul 19, 2011 3:19 pm

Hi! I'm currently using the trial version of Spire, pending the purchase approval through my company. I have my application setup to convert Office (primarialy Word and Excel) documents to PDF and they seem to be converting fine. The issue I'm having is merging existing PDF files with those I convert. When doing so, the first 2 or 3 appear to merge just fine, then the remaining files in the batch end up blank. I've used multiple methods to merge, including your demo/example on appending pages. I've also used a different merge component with close to the same results. So I'm not sure if they're actually converting the Office documents successfully afterall. Any thoughts and/or suggestions? Thanks in advance.
Posts: 1
Joined: Tue Jul 19, 2011 3:10 pm

Re: Spire PDF File Merge

Postby Justin Weng » Wed Jul 20, 2011 6:22 am

Dear grahamjg,
Thanks for your inquiry.
Would you please upload your demo and pdf files to us so that we can review your code and reproduce your problem and fix it.
Technical Support / Developer,
e-iceblue Support Team
User avatar
Justin Weng
Posts: 110
Joined: Mon Mar 28, 2011 5:54 am

Re: Spire PDF File Merge

Postby rtenger » Wed Nov 09, 2011 7:34 am

Only the first three documents will be merge. My code in vb.net:

7: Dim files() As String = {"C:\Temp\Temp_NetzControlElektro\PDF\0.pdf", "C:\Temp\Temp_NetzControlElektro\PDF\1.pdf", "C:\Temp\Temp_NetzControlElektro\PDF\2.pdf", _
"C:\Temp\Temp_NetzControlElektro\PDF\3.pdf", "C:\Temp\Temp_NetzControlElektro\PDF\4.pdf", "C:\Temp\Temp_NetzControlElektro\PDF\5.pdf"}
9: Dim docs(files.Length - 1) As PdfDocument
10: For i As Integer = 0 To files.Length - 1
11: docs(i) = New PdfDocument(files(i))
12: Next i
15: docs(0).AppendPage(docs(1))
18: For i As Integer = 0 To docs(2).Pages.Count - 1 Step 2
19: docs(0).InsertPage(docs(2), i)
20: Next i
23: docs(0).SaveToFile("MergeDocuments.pdf")
26: For Each doc As PdfDocument In docs
27: doc.Close()
28: Next doc
31: Process.Start("MergeDocuments.pdf")

Please help me
Posts: 1
Joined: Mon Oct 17, 2011 6:20 am

Re: Spire PDF File Merge

Postby Tina.Lin » Thu Nov 10, 2011 8:44 am

Hello rtenger,

Sorry for late reply and thank you for inquiry.

I attached a demo. You can have a try.

If you still have any other question, please don't hesitate to contact us.

Have a nice day.
You do not have the required permissions to view the files attached to this post.
Technical Support/Developer,
e-iceblue Support Team
User avatar
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

Re: Spire PDF File Merge

Postby PeteBSC » Sat Nov 09, 2013 9:58 pm

I've run into the same issue; however, my challenge is that I have a single PDF and for every 30 page (and remainder of) need to create a new pdf (leaving the original intact).

Code: Select all
 Dim pdfDoc As New Spire.Pdf.PdfDocument(item.FileName)  'open existing file
            Dim newDoc As Spire.Pdf.PdfDocument
            Dim startPage As Integer = 0 'first page starts at 0 index
            Dim endPage As Integer = -1 'when incremented for first page will be 0

            Using pdfDoc

                For i As Integer = 1 To item.DocumentSegments
                    imageFileName = IO.Path.Combine(basePath, item.BuildDestinationFileName(i))

                    newDoc = New Spire.Pdf.PdfDocument()

                    'calculate start and end
                    startPage = endPage + 1
                    endPage = (30 * i) - 1

                    'prevent going out of bounds
                    If endPage > item.PageCount Then
                        endPage = item.PageCount - 1
                    End If

                    Using newDoc
                        'copy current segment to new pdf file
                        For j As Integer = startPage To endPage
                            newDoc.InsertPage(pdfDoc, j)


                        If Not IO.File.Exists(imageFileName) Then
                            Return False
                            'save the split file in case we need to roll back
                        End If
                    End Using


            End Using
You do not have the required permissions to view the files attached to this post.
Posts: 1
Joined: Sat Nov 09, 2013 8:55 pm

Re: Spire PDF File Merge

Postby Gary.zhang » Mon Nov 11, 2013 6:55 am


Sorry for late reply as weekend and thanks for your inquiry.
For your needs, you could refer to the following method, if the issue still exists, could you please provide us your document(zip it before uploading or send it to our E-mail:Support@e-iceblue.com)

Code: Select all
Sub Main()
        Dim doc As New PdfDocument(your pdf document)
        Dim startPage As Integer = 0
        Dim endPage As Integer = -1
        Dim filename As String = Nothing
        For i As Integer = 1 To doc.Pages.Count - 1
            Dim newdoc As New PdfDocument()
            Dim sec As PdfSection = newdoc.Sections.Add()
            startPage = endPage + 1
            endPage = 30 * i
            If endPage > doc.Pages.Count Then
                endPage = doc.Pages.Count
            End If
            If startPage > endPage Then
                Exit For
            End If
            filename = String.Format("..\..\original-{0}-{1}.pdf", startPage, endPage)
            For j As Integer = startPage To endPage - 1
                Dim newdocpage As PdfPageBase = sec.Pages.Add()
                doc.Pages(j).CreateTemplate().Draw(newdocpage, 0, 0)
            newdoc.SaveToFile(filename, FileFormat.PDF)
    End Sub

E-iceblue support team
User avatar
Posts: 1390
Joined: Thu Apr 04, 2013 1:30 am

Re: Spire PDF File Merge

Postby amy.zhao » Thu Nov 14, 2013 9:29 am


Did you try the solution which Gary provided you? Did it resolve your issue?
Thanks for your feedback.

Best regards,
E-iceblue support team
User avatar
Posts: 2241
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF

Who is online

Users browsing this forum: No registered users and 0 guests