0

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?

4

2 回答 2

0

您发布的代码应该像在 VBScript 中一样工作

VarType(Array(...)) = VarType(myFiles) = VarType(Split(...)) = 8204

8204 = 0x200C,即VT_ARRAY | VT_VARIANTobject[]在 .NET 中确实可以翻译

因此,实际代码与此处显示的示例不同。

于 2013-02-21T12:45:33.013 回答
0

在 ASP 中定义一个动态数组,比如ReDim myFiles(max_count)max_count 是一个数值会导致问题。Dim myFiles(10) 作为测试,例如 Simon 测试的工作。

@Simon,请将您的评论设置为答案,以便我接受。

于 2013-02-21T11:30:00.950 回答