Multiple pages Header and footer page numbers Graphic on each page style body min height 900px style iframe width 95 height 800px iframe script src https github com devongovett pdfkit releases download v0 10 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 let pageNumber 0 doc on pageAdded pageNumber Add page number to the bottom of the every page doc fontSize 18 fillColor deeppink text pageNumber 72 72 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 console log loading image const logop await fetch https source unsplash com 600x400 beach const logo await logop arrayBuffer doc opacity 0 2 image logo 10 200 width 150 height 150 doc opacity 1 0 image logo 200 400 width 50 height 50 console log adding text doc fontSize 8 opacity 1 0 font Helvetica lineGap 2 fillColor green text text repeat 200 align justify 0 0 align left let words beach building cat technology for let i 0 i words length i doc addPage doc fontSize 20 text Graphic i 10 50 console log loading image const logop await fetch https source unsplash com 600x400 words i const logo await logop arrayBuffer doc opacity 1 0 image logo 10 100 width doc page width 20 console log adding header and footers Global Edits to All Pages Header Footer etc let pages doc bufferedPageRange for let i 0 i pages count i doc switchToPage i doc fillAndStroke blue moveTo 10 15 lineTo doc page width 10 15 stroke doc fillAndStroke green moveTo 10 doc page height 15 lineTo doc page width 10 doc page height 15 stroke doc fontSize 6 fillColor blue moveTo 0 0 text Page i 1 of pages count 10 15 6 lineBreak false continued false let w doc fontSize 6 widthOfString notebook xbdev net doc fontSize 6 fillColor green moveTo 0 0 text notebook xbdev net doc page width 10 w doc page height 15 2 lineBreak false continued false align right 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
doc fontSize 20 text Graphic i 10 50 console log loading image const logop await fetch https source unsplash com 600x400 words i const logo await logop arrayBuffer doc opacity 1 0 image logo 10 100 width doc page width 20 console log adding header and footers Global Edits to All Pages Header Footer etc let pages doc bufferedPageRange for let i 0 i pages count i doc switchToPage i doc fillAndStroke blue moveTo 10 15 lineTo doc page width 10 15 stroke doc fillAndStroke green moveTo 10 doc page height 15 lineTo doc page width 10 doc page height 15 stroke doc fontSize 6 fillColor blue moveTo 0 0 text Page i 1 of pages count 10 15 6 lineBreak false continued false let w doc fontSize 6 widthOfString notebook xbdev net doc fontSize 6 fillColor green moveTo 0 0 text notebook xbdev net doc page width 10 w doc page height 15 2 lineBreak false continued false align right 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