Search code examples
javascriptpdfpdfmake

pdf make in a single file


Hey i am facing a probleme with exporting pdf make functionality:

var pdfMake = require('pdfmake/build/pdfmake.js');
var pdfFonts = require('pdfmake/build/vfs_fonts.js');
pdfMake.vfs = pdfFonts.pdfMake.vfs;

export default pdfMake;

import the file with a custom webpack alias as pdfMakeGenerator:

const pdfMake = require('pdfMakeGenerator');
pdfMake.createPdf(docDefinition).download("test");

this gives me an error like:

pdfMake.createPdf is not a function

Solution

  • My solution was doing it this way:

    var pdf = require('pdfmake/build/pdfmake.js');
    var pdfFonts = require('pdfmake/build/vfs_fonts.js');
    pdf.vfs = pdfFonts.pdfMake.vfs;
    
    export const pdfMake = pdf;
    

    then

    const { pdfMake } = require('pdfMakeGenerator');