AnsweredAssumed Answered

Unable to download a PDF through JS

Question asked by Artis Plocins on May 18, 2018
Latest reply on May 24, 2018 by Francesca Shiekh

When I use app.api.fileDownload() to download a PDF file generated by SugarPDF (TCPDF) sent inline to the browser I get a warning message in Chrome (or just a TCPDF version message in Firefox) and never receive the generated file.

 

The Chrome message says:

Resource interpreted as Document but transferred with MIME type application/pdf: <URL>

You can test this instantly in any Sugar 7 instance with the following snippet in the JS console of your browser:

let url = '?module=Contacts&action=sugarpdf&sugarpdf=Test';
App.api.fileDownload(url, {
    success: console.log,
    error: console.error
}, {
    iframe: App.controller.layout.$el
});

 

And to check if that URL indeed generates a PDF file, simply open a URL like this in another tab of your browser:

https://<sugar-url>/?module=Contacts&action=sugarpdf&sugarpdf=Test

This will give you an error message PDF file with details about the error and this title (doesn't matter that it's an error, it's still a PDF file and the download result is the same even with real PDF templates):

Tcpdf class for this module and action has not been implemented.

 

I've tried adding some MIME types to the .htaccess as I found suggested on StackOverflow, but no success so far.

Do you know how to get the browser to properly force a download of a PDF file from Sugar?

Outcomes