Use Draw.io to easily create a template svg with sophisticated design, use it to generate PNG/ SVG files, and turn into both vector and raster PDF.
This template utilize Draw.io, sheetjs, pdfkit and jszip together.
'svg-to-pngpdf.js' is for batch Raster PDF creation, and also put PNG into zip.
'svg-to-svgpdf.js' is for batch Vector PDF creation, and also put SVG into zip.
'pdfDataReplace.js' is for logic processing and replacing '@XXXX' fields in templates (svg from draw.io).
'processor.js' is for handling all other looping processes.
You may read, copy and edit upon this template to quickly create other PDF Mass generation tools, or Mass produce PNG/SVG.
- Install the fonts inside the 'src' folder, then close all browser.
- Run zGenPDF.bat,or host './src' folder and run index.html yourself.
- Click ‘Choose File' , select the 'SMALL-SAMPLE-EXCEL.xlsx' file , Click 'Submit
- Wait for 'Completed'
- Download PDF and zip (Auto-downloaded if browser allow)
- Draw.io to draw the template, and leaves '@XXXX' field with correct lcoation and font size.
- SVG template is created by Draw.io Advanced Export, with correct size and human readable (Can be Formatted in VSCode).
- Mongoose as (./src/zserver.exe) to host local server. Used to prevent blocked by CORS policy: Cross origin.
- sheetjs to read Excel sheet data and mass produce edited SVG
- processor.js to find and replace '@XXXX' fields with the data and export.
- canvas to generate PNG from SVG
- PDFKIT to generate Rasterized PDFs with custom font embed (system installed)
- PDFKIT to generate Vectorized PDFs with custom font embed (.otf)
- jszip to pack SVGs and PNGs into ZIP
- Do not support wrapping long text in text box yet, need heavy modification to svg-to-pdfkit to implement. Suggest adding auto break line function in processor.js or in Excel data source.
- In Draw.io do not use 'Formatted Text' option or 'Word Wrap' option, as this will create a 'foreignObject' which is only available in SVG 1.1, and not supported by svg-to-pdfkit.
- Client do not need font to read generated Vectorized PDF, Rasterized PDF and PNG, but SVG is still editable and not have font embed. (Read tutorial page 2 for details).
- Do not choose 'embed font' option in draw.io's normal SVG export, as it will make the final Vector PDF massive. Use register font in PDFkit instead, like in this template.