我有两个代码:
string fileInput = @"c:\temp\input.pdf";
string fileOutput = @"c:\temp\saida.pdf";
PdfReader reader = new PdfReader(fileInput);
Stream output = new System.IO.FileStream(fileOutput, System.IO.FileMode.Create);
Document doc = new Document();
PdfCopy writer = new PdfCopy(doc, output);
doc.Open();
PdfImportedPage pagina = writer.GetImportedPage(reader, 23);
writer.AddPage(pagina);
doc.Close();
output.Close();
它工作得很好!该文件有 46.451 字节
但我需要使用内存而不是文件。所以我尝试了下一个代码:
string fileInput = @"c:\temp\input.pdf";
string fileOutput = @"c:\temp\saida.pdf";
PdfReader reader = new PdfReader(fileInput);
//Stream output = new System.IO.FileStream(fileOutput, System.IO.FileMode.Create);
MemoryStream output = new MemoryStream();
Document doc = new Document();
PdfCopy writer = new PdfCopy(doc, output);
doc.Open();
PdfImportedPage pagina = writer.GetImportedPage(reader, 23);
writer.AddPage(pagina);
//Added line. Just to compare...
output.WriteTo(new FileStream(fileOutput, FileMode.Create, System.IO.FileAccess.Write));
doc.Close();
output.Close();
该文件有 45.582 字节。Acrobat Reader 告诉我文件已损坏。我做错了什么?
谢谢!