Skip to content

Instantly share code, notes, and snippets.

@programmeruser2
Created July 14, 2021 02:11
Show Gist options
  • Save programmeruser2/4ac2642f01185b4724c1668add57d7ff to your computer and use it in GitHub Desktop.
Save programmeruser2/4ac2642f01185b4724c1668add57d7ff to your computer and use it in GitHub Desktop.
const iframe = document.getElementById('iframe'); //OR WHATEVER
// create a document and pipe to a blob
var doc = new PDFDocument();
var stream = doc.pipe(blobStream());
const data = 'YOUR DATA WITH TERM/MEANING SEPERATED BY TAB (\t) AND CARDS SEPERATED WITH A NEWLINE';
//console.log(data);
const cards = data.split('\n');
const allPages = [];
cards.forEach(card => {
const [a,b] = card.split('\t');
allPages.push(a);
allPages.push(b);
})
allPages.forEach(item => {
doc.text(item);
doc.addPage();
})
doc.end();
stream.on('finish', function() {
iframe.src = stream.toBlobURL('application/pdf');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment