PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

PDF opening in browser window
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1183
Page 1 of 1

Author:  pb2000 [ Thu May 13, 2010 12:34 pm ]
Post subject:  PDF opening in browser window

Hello,
I finish creating PDF with the following piece of code.
Code:
pdfRenderer.Save(filename);
Process.Start(filename);


First line saves file into hdd, second opens default system PDF reader.

I would like to obtain another scenario, namely:
Code:
IF  (Client system web browser has possibillity of opening pdf in its window)
   Open created PDF in browser;
ELSE
   Show default download window "Would You Like to save the file...." i client browser.

I would be grateful for Your help on this issue.
Than You in advance.

Paul

Author:  Rob [ Mon May 17, 2010 12:05 pm ]
Post subject:  Re: PDF opening in browser window

Code:
 
      using(MemoryStream stream = new MemoryStream())
      {
        pDoc.Save(stream, false);
        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", pFilename));
        Response.Expires = -1;
        Response.AddHeader("content-length", stream.Length.ToString());
        Response.BinaryWrite(stream.ToArray());
        Response.Flush();
      }
      Response.End();


pDoc is your pdfRenderer. If you use this code statement, a "save to ..." dialog appears always.

If you remove the line with 'Content-Disposition' you get browser dependent behaviour (inline view, save dialog). You may try other Content-Disposition settings instead of 'attachment'.

Regards,
Rob.

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