Skip to content

Instantly share code, notes, and snippets.

@sagar290
Created November 27, 2022 18:23
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 sagar290/0b9f4cea88ba335fd4da54cd49f1d5c6 to your computer and use it in GitHub Desktop.
Save sagar290/0b9f4cea88ba335fd4da54cd49f1d5c6 to your computer and use it in GitHub Desktop.
Satori pdf generation sample code
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