开发者

Create pdf document from System.IO.Stream object?

I have Str开发者_JAVA技巧eam object that contains data that i want to show in PDF document.

How do i create and Save PDF document from that Stream object? (The Stream object is created using MigraDoc tool)


I think you may be confused. MigraDoc creates Pdf documents. So if you have a stream from MigraDoc (which comes from it's PdfDocument object) I would guess that saving the stream to disk as "document.pdf" would be the best option.

See Jon Skeets answer to this here:

How do I save a stream to a file in C#?

Remember a stream is simply binary data. So when you want to read and write that data you use System.IO to read or write the stream into some location be it disk, memory or a network transmission.

I would take a look at the MigraDoc samples for more info:

http://www.pdfsharp.net/wiki/MigraDocSamples.ashx

if you are writing this to an HTTP output then I would do as follows:

byte[] buffer = new byte[8192];

pdfStream.Seek(0, SeekOrigin.Begin);

Response.ClearContent();
Response.ClearHeaders();
Response.BufferOutput = true;
Response.ContentType = "application/pdf";

int bytesRead = pdfStream.Read(buffer, 0, 8192);
while(bytesRead > 0)
{
byte[] buffer2 = new byte[bytesRead];
System.Buffer.BlockCopy(buffer, 0, buffer2, 0, bytesRead);

Response.BinaryWrite(buffer2);
Response.Flush();

bytesRead = pdfStream.Read(buffer, 0, 8192);
}
Response.End();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜