Notebooks 2.0 is here.
Read the preview announcement
Platform
Resources
Pricing
Sign in
Get started
ƒ
Workspace
Fork
Published
By
ƒ
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
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
PDFDocument
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
blobStream
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML