Created
November 27, 2022 18:23
-
-
Save sagar290/0b9f4cea88ba335fd4da54cd49f1d5c6 to your computer and use it in GitHub Desktop.
Satori pdf generation sample code
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
console.log('Hello World'); | |
import satori from 'satori' | |
import { SatoriOptions } from 'satori'; | |
import * as fs from 'fs'; | |
import SVGtoPDF from 'svg-to-pdfkit'; | |
import PDFKit from 'pdfkit'; | |
const options: SatoriOptions = { | |
width: 100, | |
height: 100, | |
fonts: [ | |
{ | |
data: fs.readFileSync('./src/fonts/Roboto-Regular.ttf'), | |
name: 'Roboto', | |
weight: 400, | |
style: 'normal' | |
} | |
] | |
} | |
async function generatePdf() { | |
let output = fs.createWriteStream('output.pdf'); | |
const response = await satori( | |
{ | |
type: 'div', | |
props: { | |
children: 'hello, world', | |
style: { color: 'black' }, | |
}, | |
}, | |
options | |
) | |
const doc = new PDFKit({ | |
layout: 'landscape', | |
size: [100, 100], | |
}); | |
// SVGtoPDF(response, response); | |
SVGtoPDF(doc, response) | |
doc.pipe(output); | |
doc.end(); | |
} | |
generatePdf() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment