多個PDF我嘗試多個PDF合併成單一的PDF。 PDFs來自SSRS,來自我處理的一些LocalReports。我正在使用PDFSharp,因爲它已在整個項目中使用。但是,outputDocument.addPage(page)方法會引發InvalidOperationException(「無法更改文檔」)異常。我試圖做的許多不同的方式,但我不能得到它的工作...結合使用PDFSharp
這裏我的方法,所有的投入都已經被檢查:
private static void saveFile(string fileName, params byte[][] bytes)
{
try
{
PdfDocument outputDocument = new PdfDocument();
for (int i = 0; i < bytes.Length; i++)
{
using (MemoryStream stream = new MemoryStream(bytes[i]))
{
PdfDocument inputDocument = PdfReader.Open(stream, PdfDocumentOpenMode.Import);
foreach (PdfPage page in inputDocument.Pages)
{
outputDocument.AddPage(page); //throws the exception !!!
}
}
}
outputDocument.Save(fileName);
}
catch (Exception ex)
{
throw new Exception("Erreur lors de l'enregistrement du fichier", ex);
}
}
從我的例子看到在網絡上,這似乎是這樣做的正確的方式... 我打開其他建議合併我的PDF文件,但我寧可不使用其他第三方的lib,就像iTextSharp的,因爲PDFSharp在已經使用該項目。
如果它的事項,我使用的是Win7的機器上VS2010專業版。
編輯:
在PdfSharp.Pdf.PdfObject.set_Document(PdfDocument值)
在PdfSharp.Pdf.PdfObject.ImportClosure(PdfImportedObjectTable importedObjectTable,PdfDocument所有者,PdfObject externalObject)
:從異常調用堆棧在PdfSharp.Pdf.PdfPages.CloneElement(PdfPage頁,PdfPage importPage,串鍵,布爾deepcopy的)
在PdfSharp.Pdf.PdfPages.ImportExternalPage(PdfPage importPage)
在PdfSharp.Pdf.PdfPages.Insert(的Int32指數,PdfPage頁)
a噸PdfSharp.Pdf.PdfPages.Add(PdfPage頁)
在PdfSharp.Pdf.PdfDocument.AddPage(PdfPage頁)
在Something.saveFile(字符串文件名,字節[] []字節)
問題是可我 ?這是不是應該這樣做? 或者是否有其他方式將多個LocalReport合併到一個PDF中?
出現InvalidOperationException – 2011-02-14 18:44:35
能否請您提供從Exception調用堆棧? – asgerhallas 2011-02-14 18:58:47