私はPDFsharpプロジェクトを使用して、多くのpdfドキュメントを1つのファイルにマージし、完全かつスムーズに機能します。ただし、従来のASPサーバーページからこのメソッドを呼び出す必要もあります。
同様に機能しますが、奇妙なことに、メソッドを呼び出してparam値を処理します。
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()型のオブジェクトです。
それで、なぜこれが異なって扱われるのか、誰かが手がかりを持っていますか?