Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Sep 09, 2013 5:59 am

I am using Spire PDF. My program has in the region of 116,000 pdf files which represent individual pages of music. I need to merge between 1 and 20 of these pages into one pdf per titles.

I have a routine the builds a string of filenames to be added to an array which is passed to the following sub as PDFFiles. The OutputFile is the string with the name of the output file with it's path.

Code: Select all
Private Sub MergePDFs(ByVal PDFFiles As String, ByVal OutPutFile As String)
    Dim files As [String]() = New [String]() {"E:\Ballads of the 20th Century\1st bari #1.pdf", "E:\Ballads of the 20th Century\1st bari #2.pdf"}
    Dim i As Integer
    'open pdf documents           
    Dim docs As PdfDocument() = New PdfDocument(files.Length - 1) {}
    For i = 0 To files.Length - 1
        docs(i) = New PdfDocument(files(i)) 'line causing error
    Next

    'append document
    docs(0).AppendPage(docs(1))

    'import PDF pages
    i = 0
    While i < docs(2).Pages.Count
        docs(0).InsertPage(docs(2), i)
        i = i + 2
    End While
End Sub


In the Solution Explorer I have the Spire.Pdf.dll as a file. In References I have Spire.Pdf and Spire.Licence.

At runtime I get An unhandled exception of type 'System.ArgumentException' occurred in Spire.Pdf.dll Additional information: File doesn't exist.

The PDFFiles is not used in this example for clarity. The two files listed are taken directly from the program output for testing purposes.

There has to be a simple explanation for this error, but I haven't found one yet.

Please can you help solve it. Thanks Graham

Penfound
 
Posts: 3
Joined: Tue Jul 02, 2013 10:07 am

Mon Sep 09, 2013 9:10 am

Dear Penfound,

Thanks for your inquiry.
The error is most likely caused by there is not the file named 1st bari #1.pdf or the file named 1st bari #2.pdf under the folder E:\Ballads of the 20th Century. Please ensure that there are your test files under the folder before loading the files.

Please wirte to us again in case you have further problems..

Best regards,
Amy
E-iceblue support team
User avatar

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

Mon Sep 09, 2013 12:01 pm

Thanks for the rely, but unfortunately, a missing fileis not the problem.It was at one time but I corrected that mistake.

I think the problem lies in the way the array itself is formed. With two files asin the example I should get an array like this...

so that when I click on files in this line

docs(i) = New PdfDocument(files(i)) 'line causing error

I should see...
0: "E:\Ballads of the 20th Century\1st bari #1.pdf"
1: "E:\Ballads of the 20th Century\1st bari #2.pdf"

instead I see

0: "E:\Ballads of the 20th Century\1st bari #1.pdf", "E:\Ballads of the 20th Century\1st bari #2.pdf"

Over to you:)
Graham

Penfound
 
Posts: 3
Joined: Tue Jul 02, 2013 10:07 am

Tue Sep 10, 2013 3:05 am

Dear Graham,

Thanks for your further attention.
I didn't reproduce the problem about files array here. I tested the below code which worked well, attached some screenshots of debuging.
Code: Select all
 Dim files As [String]() = New [String]() {"E:\PDF files\Sample1.pdf", "E:\PDF files\Sample2.pdf"}
        Dim i As Integer
        'open pdf documents           
        Dim docs As PdfDocument() = New PdfDocument(files.Length - 1) {}
        For i = 0 To files.Length - 1
            docs(i) = New PdfDocument(files(i))
        Next

        'append document
        docs(0).AppendPage(docs(1))


Please tell us in case you have further findings. Thank you!

Best regards,
Amy
E-iceblue support team
User avatar

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

Tue Sep 10, 2013 6:45 am

The problem was:
it was the parsing of the string or [String] that caused the problem.

The solution was:
There can be no spaces in the filenames passed in the string. Simples:)

Thank you for all your help.
Graham

Penfound
 
Posts: 3
Joined: Tue Jul 02, 2013 10:07 am

Tue Sep 10, 2013 7:40 am

Dear Graham,

Thanks for sharing your solution.
Please feel free to contact us in case you have further problems.

Best regards,
Amy
E-iceblue support team
User avatar

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

Return to Spire.PDF