如何将PDFSharp对象保存到多个文件?

时间:2012-05-08 12:24:35

标签: .net exception pdf c++-cli pdfsharp

我有一个pdf sharp文档,我正在生成并将其保存到单个文件中运行良好。如果我尝试从同一个pdf文档保存到多个文件,我会收到以下错误消息:

Test Error : UnitTests.PdfFocusCalResultOutputterTester.Test_MakePDF
System.InvalidOperationException : The dictionary already has a stream.
at PdfSharp.Pdf.PdfDictionary.CreateStream(Byte[] value)
at PdfSharp.Pdf.Advanced.PdfToUnicodeMap.PrepareForSave()
at PdfSharp.Pdf.Advanced.PdfType0Font.PrepareForSave()
at PdfSharp.Pdf.Advanced.PdfFontTable.PrepareForSave()
at PdfSharp.Pdf.PdfDocument.PrepareForSave()
at PdfSharp.Pdf.PdfDocument.DoSave(PdfWriter writer)
at PdfSharp.Pdf.PdfDocument.Save(Stream stream, Boolean closeStream)
at ResultOutputter.PdfFocusCalResultOutputter.RenderToFile(String filename) in c:\projects\testing\pdffocuscalresultoutputter.cpp:line 802

我只是在我PdfSharp::Pdf::PdfDocument::Save的实例上调用PdfDocument,如下所示:

System::IO::FileStream^ s = gcnew System::IO::FileStream("firstpdf.pdf", System::IO::FileMode::Create);
m_document->Save(s, false);
s->Flush();
s->Close();

System::IO::FileStream^ s2 = gcnew System::IO::FileStream("secondpdf.pdf", System::IO::FileMode::Create);
m_document->Save(s2, false);
s2->Flush();
s2->Close();

1 个答案:

答案 0 :(得分:3)

  1. 这是PDFsharp中的错误,您的代码应该有效。
  2. 您的代码效率不高。保存一次到流,然后将该流写入两个或多个文件。