PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 04, 2024 10:21 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: MigraDoc to MemoryStream
PostPosted: Mon May 13, 2013 4:04 pm 
Offline

Joined: Mon May 13, 2013 3:49 pm
Posts: 9
Hello,

I'm new in this theme.
I have created a MigraDoc.Document to print a list of movements for my WebSite in a PDF file, implemented with MVC C#. And I would like to return a "new FileStreamResult(new MemoryStream(), "application/pdf");"

So, I would like to know how can i convert a MigraDoc.Document to a MemoryStream.

I tried to do like some examples that I found on internet. But, when I save the document in my computer and I try to open it, it have some errors and then the irregulars characters appears with a strange format and the image of the header don't appears.

Which is the best way to do?

Think, that I don't want to save the document in the server because this could be a problem with security. So, I must to try to convert in a MemoryStream to send to the browser like a file download.

Can anyone help me?

Thanks in advance
Maria


Top
 Profile  
Reply with quote  
PostPosted: Mon May 13, 2013 4:47 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Hi!

Simply render the document to PDF and specify the MemoryStream instead of a file name when calling Save (add "false" to keep the MemoryStream open).

See also:
http://www.pdfsharp.net/wiki/Clock-sample.ashx

You may have to reset the MemoryStream to position 0 if you use the stream (and not the byte[] as shown in the example).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue May 14, 2013 7:22 am 
Offline

Joined: Mon May 13, 2013 3:49 pm
Posts: 9
Thanks for the answer,

I used a MigraDoc.Document not a PDFDocument because I do the same example as Invoice http://www.pdfsharp.net/wiki/Invoice-sample.ashx

If I cannot do the render with document, how can I do this?

Is any way to implement a migradoc into a pdfdocument?

thanks in advance
Maria


Top
 Profile  
Reply with quote  
PostPosted: Tue May 14, 2013 8:03 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
The MigraDoc PdfRenderer offers the same Save methods (it uses a PdfDocument inside and the Save commands are routed through).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue May 14, 2013 10:36 am 
Offline

Joined: Mon May 13, 2013 3:49 pm
Posts: 9
Ok!!

Thanks for the answer, I will try what you said.

best regards
Maria


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 115 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group