1
votes

Using info found here and elsewhere I have successfully implemented an app that will pull a PDF from our document storage server, stream it across our firewall and display it in a frame on the client's web browser. The PDF is loaded into a page using the following code and that page is the source for the iframe.

int ImageID;
if (int.TryParse(Request.QueryString["ImageID"], out ImageID))
{
  FileTransferService.FileTransferClient client = new FileTransferService.FileTransferClient();

  Byte[] documentStream = client.GetFile(Classes.AppSettings.pwServer, Classes.AppSettings.pwDatabase, Classes.AppSettings.pwUsername, Classes.AppSettings.pwPassword, Classes.AppSettings.pwCabinet, ImageID, "", "");
  Response.ContentType = "application/pdf";
  Response.BinaryWrite(documentStream);
}

This is working fine most of the time, but due to settings on the client for the Acrobat Reader plugin the PDF will sometimes open in Acrobat Reader rather than displaying in the web page, leaving our page with an empty hole where the PDF should be. I've searched for a third party PDF viewer we could use in the app without success. Either they don't accept a stream as a source or the image quality is unacceptable. If we could force it to always pop up in Acrobat Reader that would be acceptable, but we'd prefer it to be displayed in the web page. For security reasons we don't want to write the file to disk and display it from there.

Is there a method to force the viewing behavior one way or another or a third party viewer we could use that will solve this problem?

1
Maybe you find a workaround, but in essence it will be not possible. Mainly because of the client settings of the browser which you have no control. I can configure my Adobe plugin to open the PDF files, regardless of what comes from the application server.gustavodidomenico
Although not your first choice, I wonder if 'Content-Disposition: attachment; filename="____"' would work to have it always open it the readerbdimag
@bdimag I just gave that a try and while not the ideal solution it at least makes the behavior consistent. Thank you for the suggestion. I did not know that you could tell the browser to treat a stream as a file. If you will post your suggestion as an answer I will mark it as accepted.John

1 Answers

0
votes

As an alternative to the optimal solution, you could add the 'Content-Disposition' header to make the browser always treat it as a download.

Usage:

Content-Disposition: attachment; filename="example.pdf"

This may also be worth looking into, although I've never used it: System.Net.Mime.ContentDisposition

Represents a MIME protocol Content-Disposition header.