Scenario
The following sample code can be used for creating PDF with picking tickets of transaction specified by parameter id and followed by direct download to the computer.
Solution
Modules Used: N/render
function downloadPDF(context){
var request = context.request;
var response = context.response;
var id = request.parameters.tranid;
var r = render.pickingSlip({
entityId: id,
printMode: render.PrintMode.PDF
})
response.setHeader({
name: 'Content-Type',
value: 'application/pdf'
})
response.addHeader({
name: "Content-Disposition",
value: 'attachment; filename=transaction'+id+'.pdf'
})
response.write({
output: r.getContents()
})
}