Skip to content

Instantly share code, notes, and snippets.

@rahji
Created June 27, 2024 17:06
Show Gist options
  • Save rahji/cf9f503381c2b59202af9b5833330def to your computer and use it in GitHub Desktop.
Save rahji/cf9f503381c2b59202af9b5833330def to your computer and use it in GitHub Desktop.
pdf gen test
<html>
<head>
<meta charset="utf-8" />
<script src="https://unpkg.com/pdf-lib"></script>
</head>
<body>
<iframe id="pdf" style="width: 100%; height: 100%;"></iframe>
</body>
<script>
createPdf();
async function createPdf() {
const pdfDoc = await PDFLib.PDFDocument.create();
const page = pdfDoc.addPage([350, 400]);
page.moveTo(110, 200);
page.drawText('Hello World!');
const pdfDataUri = await pdfDoc.saveAsBase64({dataUri: true});
document.getElementById('pdf').src = pdfDataUri;
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment