Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies within .NET ( C#, VB.NET, ASP.NET, .NET Core) application and Java (J2SE and J2EE) application.

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.

grahamjg
 
Posts: 1
Joined: Tue Jul 19, 2011 3:10 pm

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.
Justin
Technical Support / Developer,
e-iceblue Support Team
User avatar

Justin Weng
 
Posts: 110
Joined: Mon Mar 28, 2011 5:54 am

Wed Nov 09, 2011 7:34 am

Hi,
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
13:
15: docs(0).AppendPage(docs(1))
16:
18: For i As Integer = 0 To docs(2).Pages.Count - 1 Step 2
19: docs(0).InsertPage(docs(2), i)
20: Next i
21:
23: docs(0).SaveToFile("MergeDocuments.pdf")
24:
26: For Each doc As PdfDocument In docs
27: doc.Close()
28: Next doc
29:
31: Process.Start("MergeDocuments.pdf")

Please help me
Thanks
Roland

rtenger
 
Posts: 1
Joined: Mon Oct 17, 2011 6:20 am

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.
Tina
Technical Support/Developer,
e-iceblue Support Team
User avatar

Tina.Lin
 
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

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)
                        Next

                        newDoc.SaveToFile(imageFileName)

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

                Next

                pdfDoc.Close()
            End Using
You do not have the required permissions to view the files attached to this post.

PeteBSC
 
Posts: 1
Joined: Sat Nov 09, 2013 8:55 pm

Mon Nov 11, 2013 6:55 am

Hello,

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)
            Next
            newdoc.SaveToFile(filename, FileFormat.PDF)
        Next
    End Sub

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Thu Nov 14, 2013 9:29 am

Hello,

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

Best regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2328
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF