Created
September 13, 2021 05:26
-
-
Save Risyandi/57e5b7148871826366db19a64de0ade4 to your computer and use it in GitHub Desktop.
create pdf using pdfMake library
This file contains hidden or 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
// library pdfMake | |
import pdfMake from "pdfmake/build/pdfmake"; | |
import pdfFonts from "pdfmake/build/vfs_fonts"; | |
pdfMake.vfs = pdfFonts.pdfMake.vfs; | |
// document definition | |
let docDefinition = { | |
content: [{ | |
text: 'Report Goods Receive', | |
style: 'header' | |
}, | |
'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Confectum ponit legam, perferendis nomine miserum, animi. Moveat nesciunt triari naturam.\n\n', | |
{ | |
style: 'tableExample', | |
table: { | |
body: [ | |
['Column 1', 'Column 2', 'Column 3'], | |
['One value goes here', 'Another one here', 'OK?'], | |
['One value goes here', 'Another one here', 'OK?'], | |
] | |
} | |
}, | |
{ | |
text: '\n\n This file transmitted with it are confidential and intended solely for the use of the individual to whom it is addressed. If you have received this file in error please send it back to the person that sent it to you. Any views or opinions presented are solely those of its author and do not necessarily represent those of NABATI or any of its subsidiary companies. Unauthorized publication, use, dissemination, forwarding, printing or copying of this email and its associated attachments is strictly prohibited.', | |
style: ['quote', 'small'] | |
} | |
], | |
styles: { | |
header: { | |
fontSize: 18, | |
bold: true | |
}, | |
subheader: { | |
fontSize: 15, | |
bold: true | |
}, | |
quote: { | |
italics: true | |
}, | |
small: { | |
fontSize: 8 | |
} | |
} | |
}; | |
// generate file pdf | |
const pdfDocGenerator = pdfMake.createPdf(docDefinition); | |
pdfDocGenerator.getDataUrl((dataUrl) => { | |
const targetElement = document.querySelector('#iframeContainer'); | |
if (targetElement !== null) { | |
let element = ` | |
<iframe style="width: 100%;height: 100em;" src="${dataUrl}"> | |
</iframe>`; | |
targetElement.innerHTML = element; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment