PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Wed Dec 03, 2025 6:14 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Download file for user
PostPosted: Thu May 10, 2012 11:55 pm 
Offline

Joined: Thu May 10, 2012 11:52 pm
Posts: 7
Okay. I'm looking at samples of PDFSharp and I'm trying to let user to download generated file on the fly.

When file is generated is actually returns aspx file instead of pdf file.
here's my code:
Code:
Document document = CreateDocument();
        document.UseCmykColor = true;
        const bool unicode = false;
        const PdfFontEmbedding embedding = PdfFontEmbedding.Always;
        PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);
        pdfRenderer.Document = document;
        pdfRenderer.RenderDocument();
   
        const string filename = "HelloWorld.pdf";
        Response.ContentType = "application/pdf";
        StreamWriter s = new StreamWriter(Response.OutputStream);
        MemoryStream stream = new MemoryStream();
        Response.AddHeader("Content-Disposition", filename);
        pdfRenderer.PdfDocument.Save(stream, true);
        s.Write(stream);
        Response.Flush();
        Response.Close();


I trued many different variations but everything seems to give me back aspx file instead of pdf. Any suggestions?


Top
 Profile  
Reply with quote  
PostPosted: Fri May 11, 2012 7:35 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 355
Where do you add the stream to the Response?

Check this sample:
http://www.pdfsharp.net/wiki/Clock-sample.ashx

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Fri May 11, 2012 4:34 pm 
Offline

Joined: Thu May 10, 2012 11:52 pm
Posts: 7
Apparently, it is only happening in Chrome. IE works file and download PDF file. any suggestions? Even with Clock sample it doesn't download correctly.


Top
 Profile  
Reply with quote  
PostPosted: Sat May 12, 2012 4:57 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 355
I tried Chrome with the Clock sample running on the empira server (there's a link in the Wiki page (see the link in my earlier post)) and it worked fine.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Tue May 15, 2012 1:00 am 
Offline

Joined: Thu May 10, 2012 11:52 pm
Posts: 7
I don't know what I changed, but now it works. Something like content type of response or update panel was causing issues. Thanks a lot.


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: No registered users and 283 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