Last active
June 2, 2020 10:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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