Andrew Luke
10/18/2024, 1:35 AMCeligo AI
10/18/2024, 1:35 AMAI generated answer (using internal Slack threads):Based on the conversations, to download a PDF that is generated by a suitelet, you can use the
writeFile
method in SuiteScript. However, the key to controlling whether the PDF is displayed in the browser or downloaded directly lies in the headers that you set in your response.
Here is a code snippet that was shared in the conversations:
javascript
response.addHeader({ name: 'Content-Type:', value: 'application/pdf', });
response.addHeader({ name: 'Content-Disposition', value: 'inline; filename=\"report.pdf\"', });
renderer.renderPdfToResponse(response);
In this code, the Content-Type
header is set to application/pdf
, which tells the browser that the response is a PDF document. The Content-Disposition
header is set to inline
, which means the PDF should be displayed in the browser, and filename=\"report.pdf\"
specifies the name of the PDF when downloaded.
If you want the PDF to be downloaded directly instead of being displayed in the browser, you can change the Content-Disposition
header to attachment
like so:
javascript
response.addHeader({ name: 'Content-Disposition', value: 'attachment; filename=\"report.pdf\"', });
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
10/18/2024, 1:35 AMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.857319117
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.856086195
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.847462296
Celigo AI
10/18/2024, 1:35 AM