I use the PDFsharp project to merge many pdf documents into one file which works perfectly and smooth. But I also need to call this method from classic ASP server pages.
Works as well, but the strange thing is handling the param values by calling the method.
C# definition:
public void MergeMultiplePDF(object[] files, string outFile)
{
// note: get an array from vbscript, so files need to be a object array, not string array.
// Open the output document
PdfDocument outputDocument = new PdfDocument();
// Iterate files
foreach (string file in files)
{
// Open the document to import pages from it.
PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import);
// Iterate pages
int count = inputDocument.PageCount;
for (int idx = 0; idx < count; idx++)
{
// Get the page from the external document...
PdfSharp.Pdf.PdfPage page = inputDocument.Pages[idx];
// ...and add it to the output document.
outputDocument.AddPage(page);
}
}
// Save the document...
outputDocument.Save(outFile);
outputDocument.Dispose();
}
Call from classic ASP:
Dim l_sPath : l_sPath = "D:\test\"
oPDF.MergeMultiplePDF Array(l_sPath & "sample1.pdf", l_sPath & "sample2.pdf", l_sPath & "sample3.pdf" ), l_sPath & "output.pdf"
Works fine, as array is a object VARIANT and I handle the array inside the .NET class.
But if I have a "dynamic" array in classic ASP I get the usual error that the argument is not correct like you can find in many posts here...
Sample:
Dim myFiles(10)
For i = 0 To UBound(myFiles)
myFiles(i) = "test" & i & ".pdf"
Next
oPDF.MergeMultiplePDF myFiles, l_sPath & "output.pdf"
This run into an argument error.
My workaround:
oPDF.MergeMultiplePDF Split(Join(myFiles,","),","), l_sPath & "output.pdf"
Then it works.
Both are objects of type Array().
So anyone has a clue why this is handled different?