Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function svgtopdf (el, options, pdf) {
if (typeof el === 'string') {
const svg = svgson.parseSync(fs.readFileSync(el, 'utf-8'))
const [, , width, height] = svg.attributes.viewBox.split(' ').map(Number)
const scale = 24 / Math.min(width, height)
const pdfdoc = new PDFDocument({ size: [width * scale, height * scale] })
pdfdoc.scale(scale)
pdfdoc.pipe(fs.createWriteStream(el.replace('svg', 'pdf')))
svgtopdf(svg, { fill: '#000' }, pdfdoc)
pdfdoc.end()
} else {
for (const node of el.children) {
const fillr = (node.attributes['fill-rule'] || 'nonzero').replace(/-*(zero|odd)$/, '-$1')
const color = (val) => String(val).replace(/currentColor/i, options.color).replace(/none/i, '')
const float = (key) => Number(node.attributes[key]) || 0
const style = {}
// Style
pdf.fillColor(style.fill = color(node.attributes['fill'] || options.fill || options.color))