PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 8:21 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Jun 08, 2015 2:02 pm 
Offline

Joined: Mon Jun 08, 2015 1:44 pm
Posts: 4
I have a reporting class which returns a stream to the caller. This works with PDFs:

Code:
        protected Stream RenderToStream(Document document)
        {
            var renderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always) { Document = document };
            renderer.RenderDocument();

            var stream = new MemoryStream();
            renderer.PdfDocument.Save(stream, false);           

            stream.Seek(0, SeekOrigin.Begin);

            return stream;
        }

But if I try similar with rtfs:

Code:
        protected Stream RenderToStream(Document document)
        {
           
            //var renderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always) { Document = document };
            var renderer = new RtfDocumentRenderer();           
            var stream = new MemoryStream();
           
            renderer.Render(document, stream, WorkingPath);
                       
            //can't do this as stream is closed
            //stream.Seek(0, SeekOrigin.Begin);

            return stream;
        }

I get a stream closed error - does .Render close the stream? How do I work around so I can return a stream - I don't really want to refactor the code too much just for rtfs.

Ta.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 08, 2015 4:06 pm 
Offline
PDFsharp Guru
User avatar

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

Yes, Render() closes the stream.

You could use RenderToString to write RTF to a string. Write that string to a MemoryStream and return the open stream.

I think the option to keep the stream open will be included in the next release. Until then use RenderToString or modify version 1.32 as needed.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 09, 2015 5:45 am 
Offline

Joined: Mon Jun 08, 2015 1:44 pm
Posts: 4
Many thanks for the pointer.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 53 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