我使用PDFsharp項目將許多pdf文檔合併爲一個完美平滑的文件。 但我也需要從傳統的ASP服務器頁面調用此方法。來自經典的asp調用.NET組件方法的變體參數值
也適用,但奇怪的是通過調用方法來處理參數值。
C#定義:
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();
}
從傳統的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"
工作得很好,因爲陣列是對象VARIANT和予處理.NET類內的陣列。
但是,如果我有傳統的ASP「動態」陣列我得到的通常錯誤的說法是不正確的一樣,你可以在這裏在很多帖子找到...
樣品:
Dim myFiles(10)
For i = 0 To UBound(myFiles)
myFiles(i) = "test" & i & ".pdf"
Next
oPDF.MergeMultiplePDF myFiles, l_sPath & "output.pdf"
這會遇到參數錯誤。
我的解決方法:
oPDF.MergeMultiplePDF Split(Join(myFiles,","),","), l_sPath & "output.pdf"
然後,它的工作原理。
兩者都是Array()類型的對象。
因此,任何人都有一個線索,爲什麼這是處理不同?
他們誰倒票可以告訴我爲什麼? – YvesR 2013-02-21 08:36:04
您發佈的代碼應該工作VarType(Array ...)= VarType(myFiles)= VarType(Split ...)= 8204(變體數組)。你確定這個問題不是來自你的C#實現嗎? – 2013-02-21 08:59:52
@SimonMourier myFiles和myFiles的Split/Join的VarType()是8204,這是正確的。但將myFiles設置爲像我在示例中寫的參數,我得到一個錯誤800a0005(無效參數)。這就是爲什麼我張貼我的問題找到這種奇怪的情況的答案。在c#中它只是定義爲object [],所以這不應該和呼叫失敗,而不是方法內的代碼。 – YvesR 2013-02-21 09:27:48