Skip to content

Instantly share code, notes, and snippets.

@DannyDainton
Last active June 2, 2020 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DannyDainton/19b3e2376c8cb76f5a344bd7fedaca15 to your computer and use it in GitHub Desktop.
Save DannyDainton/19b3e2376c8cb76f5a344bd7fedaca15 to your computer and use it in GitHub Desktop.
Save a JSON response containing a base64 value to a PDF file within Postman. Added this script to the `Tests` tab and view the response in the Visualiser. Reference post - https://medium.com/younited-tech-blog/serve-yourself-combining-postman-and-express-3fd1dd9f545c
let myPDFData = {
contract: Buffer.from(pm.response.json().contract, 'base64'),
reference: pm.response.json().reference
}
let template = `
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.min.js"></script>
<button onclick="savePDF()">Save To PDF</button>
<script type="text/javascript">
function savePDF() {
let pdf = new jsPDF();
pdf.text("${myPDFData.contract}", 10, 10);
pdf.save("${myPDFData.reference}.pdf");
}
</script>
`
pm.visualizer.set(template, myPDFData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment