PDF Make Example style body min height 800px style script src https cdnjs cloudflare com ajax libs pdfmake 0 2 7 pdfmake min js script script src https cdnjs cloudflare com ajax libs pdfmake 0 2 7 vfs_fonts min js script script var vfs1 pdfMake vfs script script src https notebook xbdev net var resources vfs_fonts_times js script script var vfs2 pdfMake vfs script script src https cdn jsdelivr net npm pdfjs dist 2 0 385 build pdf min js script script src https github com devongovett pdfkit releases download v0 10 0 pdfkit standalone js script script pdfMake vfs vfs1 vfs2 make a document doc new PDFDocument let base64arr pdfMake vfs Times Regular ttf var arraybuffer Uint8Array from atob base64arr c c charCodeAt 0 doc registerFont Times Regular arraybuffer var w doc font Times Regular fontSize 50 widthOfString This is a sample text var h doc font Times Regular fontSize 50 heightOfString This is a sample text w w 72 1 h h 72 console log w w h h pdfMake fonts Roboto normal Roboto Regular ttf bold Roboto Medium ttf italics Roboto Italic ttf bolditalics Roboto Italic ttf All 4 components must be defined TimesNewRoman normal Times Regular ttf bold Times Bold ttf italics Times Italic ttf bolditalics Times BoldItalic ttf var docDefinition pageSize width 72 8 height 72 11 pageOrientation portrait pageMargins 72 72 72 72 content text This is a sample text fontSize 15 text This is a sample text fontSize 8 font TimesNewRoman text This is a sample text fontSize 50 font Roboto text This is a sample text fontSize 50 font TimesNewRoman color orange margin 0 0 0 0 absolutePosition x 0 y 0 canvas type polyline lineWidth 3 closePath true lineColor green dash length 5 space 10 points x 72 y 72 x 72 7 y 72 x 72 7 y 72 10 x 72 y 72 10 margin 0 0 0 0 absolutePosition x 0 y 0 canvas type polyline lineWidth 1 closePath true lineColor purple dash length 10 space 2 points x 72 y 72 3 x 72 w y 72 3 x 72 w y 72 3 h x 72 y 72 3 h defaultStyle font TimesNewRoman function renderPDF url canvasContainer options options options scale 1 4 function renderPage page const viewport page getViewport options scale const div document createElement div document body appendChild div div style width 500px div style height 700px const canvas document createElement canvas canvas style width 100 canvas style height 100 div appendChild canvas const ctx canvas getContext 2d const renderContext canvasContext ctx viewport viewport canvas height viewport height canvas width viewport width page render renderContext function renderPages pdfDoc for let num 1 num pdfDoc numPages num pdfDoc getPage num then renderPage PDFJS disableWorker true PDFJS getDocument url then renderPages pdfMake createPdf docDefinition getDataUrl dataURL renderPDF dataURL document getElementById canvas console log ready script
50 font TimesNewRoman color orange margin 0 0 0 0 absolutePosition x 0 y 0 canvas type polyline lineWidth 3 closePath true lineColor green dash length 5 space 10 points x 72 y 72 x 72 7 y 72 x 72 7 y 72 10 x 72 y 72 10 margin 0 0 0 0 absolutePosition x 0 y 0 canvas type polyline lineWidth 1 closePath true lineColor purple dash length 10 space 2 points x 72 y 72 3 x 72 w y 72 3 x 72 w y 72 3 h x 72 y 72 3 h defaultStyle font TimesNewRoman function renderPDF url canvasContainer options options options scale 1 4 function renderPage page const viewport page getViewport options scale const div document createElement div document body appendChild div div style width 500px div style height 700px const canvas document createElement canvas canvas style width 100 canvas style height 100 div appendChild canvas const ctx canvas getContext 2d const renderContext canvasContext ctx viewport viewport canvas height viewport height canvas width viewport width page render renderContext function renderPages pdfDoc for let num 1 num pdfDoc numPages num pdfDoc getPage num then renderPage PDFJS disableWorker true PDFJS getDocument url then renderPages pdfMake createPdf docDefinition getDataUrl dataURL renderPDF dataURL document getElementById canvas console log ready script