I am performing a server-side redirect from my entry page to a PDF output summary to maintain view state (redirect = false):

ref = new PageReference('/apex/outputPDF?id=' + accountId);
return ref;

I would like to use Chrome's built-in PDF reader so it opens a preview in Chrome rather than automatically downloading to a PDF. FWIW, Checking the box in Chrome settings to "Open PDF files in the default PDF viewer application" results in an automatic download without a preview.

The problem I am running into is that, when using the built-in reader, the only 'save as type' option is "Chrome HTML Document" and "All Files." And when I manually change the file extension from .htm to .pdf, the file will not open.

Viewing and saving works as expected when I open it through IE11, when I do a client-side redirect (redirect = true, which I don't want to do and flush the view state), and when I do a print to PDF (which I would prefer not to do, but is the current workaround). I should also add that using an iFrame as a workaround fixes the issue with Chrome, but is not compatible with IE, so I can't use that solution either. So I believe the issue is that I am viewing a PDF page without redirecting away from the non-PDF page and that is 'tricking' Chrome.

Is it possible to use Chrome's built-in PDF viewer, do a server-side redirect to my PDF page, and still be able to save as a PDF? Thanks!

Here is the apex:page line just in case it helps eliminate some potential issues:

<apex:page sidebar="false" showHeader="false" controller="Controller" renderAs="PDF" applyBodyTag="false" applyHtmlTag="false" standardStylesheets="false" contentType="application/pdf#outputPDF">  
  • As a quick guess it will be related to either the contentType or the minetype header. You need to tell the browser that the stream of incomming bytes is a PDF. – Daniel Ballinger Feb 14 '17 at 21:07
  • Try changing the filename indicated by the contentType. E.g. contentType="application/pdf#output.pdf" – Daniel Ballinger Feb 14 '17 at 21:11
  • Also, check that you aren't setting the Content-Disposition header in the controller. – Daniel Ballinger Feb 14 '17 at 21:15
  • Thanks for the ideas, @DanielBallinger. Unfortunately, I am not setting Content-Disposition anywhere and adding .pdf onto the contentType didn't solve it. Perhaps it's just not possible without redirecting to the PDF page? – mplax Feb 14 '17 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.