Home » Did you know? » How to make PDF Inline?

How to make PDF Inline?

How are headers added in the server response to make PDF Inline?

In this blog, I will be showing you how you can open your advanced PDF in a new tab. As the
The default behaviour of the browser is to download it. With the help of some quick changes, you can achieve it.

Pre-requisites
– NetSuite Account
– Knowledge of Suite Script
– Knowledge of Advanced PDF

CTA - NetSuite Homepage Banner

Assumptions
This article will not cover the PDF & button creation aspects, assuming that you are familiar with it.

Scenario
Let us suppose a button on any record in NetSuite that triggers a SuiteLet on its click to show PDF file in a new tab.

Default Behavior
Browser’s default behaviour is to download PDF instead of opening it in a new tab.

Expected Result
To open the PDF in a new tab with the click of a button.

Solution
To open PDF in a new tab after a button click, we have to change the headers of the server response object.
By default, the server response headers are set to download the PDF. The main two headers that need to be added are:

Content-Type: application/pdf” and “Content-Disposition: inline;
filename=”report.pdf’’. By default, Content-Disposition set is ’attachment’ and Content-Type is
‘application/octet-stream’, we need to change Content-Type to ‘application/octet-stream’ and
Content-Disposition to ‘inline’. Set these headers in the server’s response, and you will see the magic.

CTA - NetSuite Customization Banner

Before rendering the PDF, you must set these headers in your ‘context response object’. Here is a piece of the snippet to that:

const { response } = context;
const renderer = render.create();
response.addHeader({
name: ‘Content-Type:’,
value: ‘application/pdf’
});
response.addHeader({
name: ‘Content-Disposition’,
value: ‘inline‘
});
renderer.renderPdfToResponse({
response: response
});

Get In Touch With Our Experts


    Get In Touch With Our Experts

      I have read and agree to the Privacy Policy of Folio3
      I agree to be contacted by Phone or Email by Folio3

      Get in touch with the

      Award-Winning

      End-to-end NetSuite Servicing Agency

      Tell us how may we assist you!