Published
Edited
Sep 13, 2019
1 fork
1 star
Insert cell
md`# Hello, pdfkit!

[standalone pdfkit](https://github.com/foliojs/pdfkit/releases/download/v0.10.0/pdfkit.standalone.js)
`
Insert cell
{
return new Promise ((resolve, reject) => {
// create a document the same way as above
const doc = new PDFDocument()
doc.path('M 0,20 L 100,160 Q 130,200 150,120 C 190,-40 200,200 300,150 L 400,90')
.stroke()

// get a blob when you're done
doc.end()

// pipe the document to a blob
const stream = doc.pipe(blobStream())

// add your content to the document here, as usual
stream.on('finish', () => {
const url = stream.toBlobURL('application/pdf')
resolve(html`<a href="${url}" target="_blank">Generated PDF</a>`)
}).on('error', reject)
})
}
Insert cell
// TODO: already a minified version published somewhere?
PDFDocument = require('https://github.com/foliojs/pdfkit/releases/download/v0.10.0/pdfkit.standalone.js')
Insert cell
blobStream = require('https://bundle.run/blob-stream@0.1.3')
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more