Text with border region style body min height 900px style iframe width 95 height 800px iframe script src https github com devongovett pdfkit releases download v0 11 0 pdfkit standalone js script script src https github com devongovett blob stream releases download v0 1 3 blob stream js script script async console log setting up pdf document var doc new PDFDocument size 5 72 8 72 72 per inch margins top 20 left 10 right 10 bottom 20 bufferPages true var stream doc pipe blobStream doc rect 200 20 90 90 fillAndStroke orange black let text Some text with standard font doc fontSize 5 fillColor black text text repeat 50 width 200 10 let fh 20 doc fontSize fh var g 4 var txt Your text here is repeat 2 var r x 60 y 240 w 230 h 0 r h doc heightOfString txt width r w lineGap 0 doc rect r x r y r w r h 5 fillAndStroke ddd 000 stroke 222 fill 00f fill f00 fill transparent text txt r x 1 r y width r w height r h console log end pdf get a blob when you re done doc end var blob stream on finish function console log finished outputing pdf get a blob you can do whatever you like with blob stream toBlob application pdf or get a blob URL for display in the browser const url stream toBlobURL application pdf const iframe document querySelector iframe iframe src url console log ready script
h var g 4 var txt Your text here is repeat 2 var r x 60 y 240 w 230 h 0 r h doc heightOfString txt width r w lineGap 0 doc rect r x r y r w r h 5 fillAndStroke ddd 000 stroke 222 fill 00f fill f00 fill transparent text txt r x 1 r y width r w height r h console log end pdf get a blob when you re done doc end var blob stream on finish function console log finished outputing pdf get a blob you can do whatever you like with blob stream toBlob application pdf or get a blob URL for display in the browser const url stream toBlobURL application pdf const iframe document querySelector iframe iframe src url console log ready script