Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Force PDF download instead of browser open

Avatar

Level 2

Is there a way to force a PDF rendered by LC to be downloaded by the HTML client, instead of opened in the browser? When I use the REST url the browser tries to open the PDF and I don't get the download option.

5 Replies

Avatar

Level 8

I believe that this is actually caused by the broswer.  The service sends a file to the client (a browser in this case) of type "application/pdf".  The browser then says: "Hey, I know what to do with that.  I'll open Reader/Acrobat".  This is because of the association made in the browser with application/pdf files and Reader/Acrobat.

If on the other hand, you change the content type in the resulting document object (say using a setValue in a LC process) to something like "mysterious/unknown" then the browser sees the file it can't make an association.  That should trigger a download dialog.

Avatar

Level 2

Hmm.. I have the impression I need to do something more thank just that. Indeed I got the popup to work by changing the MIME type, but that also removed the .pdf extension for some reason. I'f I keep using PDF the browser just always opens it, whilst that same browser on many other sites forces the download dialog when opening PDFs.

More hints are welcomed

Avatar

Employee

You can do that by adding a http header in the response, for instance in a servlet you would add:

response.addHeader("content-disposition", "attachment; filename=" + myFileName + ".pdf")

Avatar

Level 2

Hmmm... I am invoking the process through a REST interface. I guess there is no way to set the HTTP header just straight from within Workbench for that REST service?

Avatar

Employee

I haven't seen any configuration option on the REST end point.

Anyway loading a LiveCycle REST end point as a web page directly into a HTML browser is not a common real life scenario, is it?

A typical architecture would include a web application and the REST end point would be invoked through a servlet, or maybe through a URL reference in another web page.