PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

output stream filename
http://forum.pdfsharp.com/viewtopic.php?f=2&t=818
Page 1 of 1

Author:  mikesowerbutts [ Wed Jul 29, 2009 9:25 am ]
Post subject:  output stream filename

Hi All,

I am outputting my PDF to the browser using Response. Its all working perfectly except I cant get the PDF to use the filename I want it to - it always comes up with a few random numbers/letters. I have tried using
Code:
Response.AddHeader("Content-Disposition", "inline;filename=myPDFFilename.pdf")

when creating the PDF, but it doesnt seem to make any difference in Firefox, but works in IE 7...

here is the code in my save function:
Code:
protected void savePDF(PdfDocument pdfDocument)
{
            // Send PDF to browser
            MemoryStream stream = new MemoryStream();
            pdfDocument.Save(stream, false);
            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "inline;filename=myPDFFilename.pdf");
 
            Response.AddHeader("content-length", stream.Length.ToString());
            Response.BinaryWrite(stream.ToArray());
            Response.Flush();
            stream.Close();
            Response.End();
        }

Can I set a property of the PdfDocument object I am saving which will also set the filename? or does it have to be specifically in the Response.AddHeader()?

Also, if i change the "inline" to "attachment", the filename i set appears in the save as dialog, even in FF!

Mike

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/