Reputation: 2089
I've tried many things to get this to work, if I use
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", newFileInfo.Name));
instead of
Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", newFileInfo.Name));
It works, but I need this to display in the browser window to work properly. The inline view works properly in Chrome. I've tried using Response.BinaryWrite and Response.WriteFile and it made no difference.
I'm using Internet Explorer 9.
Here is my code:
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Pragma", "public");
Response.AddHeader("expires", "0");
Response.AddHeader("Cache-Control", "no-cache");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
string filePath = Request["file"];
string signatureFile = Request["SignatureImage"];
double xPos = Convert.ToDouble(Request["X-Pos"]);
double yPos = Convert.ToDouble(Request["Y-Pos"]);
double scale = Convert.ToDouble(Request["Scale"]);
if (!string.IsNullOrEmpty(filePath))
{
try
{
string newFile = PDFTools.SignPDF(filePath, signatureFile, xPos, yPos, scale, tempDirectory);
var newFileInfo = new FileInfo(newFile);
Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", newFileInfo.Name));
Response.AddHeader("content-length", newFileInfo.Length.ToString());
Response.TransmitFile(newFile);
Response.Flush();
Response.Close();
}
catch (Exception ex)
{
Debug.WriteLine("Error: " + ex.Message);
Debug.WriteLine("at " + ex.StackTrace);
}
finally
{
Response.End();
}
}
Thanks for your time!
Upvotes: 2
Views: 1745
Reputation: 1734
Chrome has a built-in PDF viewer, but Internet Explorer does not. Do you have an external PDF viewer (i.e., Adobe Acrobat or Adobe Reader) installed and configured for web view?
Sorry, no rep, can't post comments.
Upvotes: 4