3

I'm just going to build an application in Webpack and would like to integrate pdfmake unfortunately I encounter this problems. I have the file "pdfmake.js" are in my "web_modules" folder and put them with

Var pdfmake = require(" pdfmake ");

When I call the:

pdfMake.createPdf(docDefinition).open ();

doing, he tells me "CreatePDF" is not a function that has struck me, and I found that I call the "File Saver" and not "pdfmake" get back at these locations. Has this happened to anyone of you have an idea? Thanks for your help!

circy
  • 199
  • 1
  • 3
  • 10
  • i solved my problem with the following code line: **require("script!pdfmake");** You have to use the scriptloader from webpack. – circy Dec 11 '14 at 11:33
  • pdfmake is exposing different apis depending on the environment (which is not good imho). I've [opened an issue](https://github.com/bpampuch/pdfmake/issues/150) for that. – Johannes Ewald Dec 12 '14 at 09:57
  • @circy Can you move that comment as an answer and mark it as a solution? Thanks. – Juho Vepsäläinen Apr 23 '15 at 06:29

1 Answers1

1

i solved my problem with the following code line: require("script!pdfmake"); You have to use the scriptloader from webpack.

circy
  • 199
  • 1
  • 3
  • 10
  • can you please show me your config, i can't for the life of me use this library with webpack – Agamennon Nov 10 '15 at 07:02
  • If you webpack and pdfmake lib from the build folder [link](https://github.com/bpampuch/pdfmake/tree/master/build) used it would have to go is white following. require("script!**./Path to the lib pdfmake***"); Then you can run without what to initialize the following command immediately: pdfMake.createPdf(docDefinition) – circy Nov 11 '15 at 12:52
  • 1
    If you NPM USER it's even easier. NPM install pdfmake npm install pdfmake var PdfPrinter = require('pdfmake'); var fonts = { Roboto: { normal: 'citycontrasts.ttf' } }; var printer = new PdfPrinter(fonts); var pdfDoc = printer.createPdfKitDocument(docDefinition); So it should also run without Problehme in Webpack. – circy Nov 11 '15 at 13:00
  • 1
    Are you sure this works? I've replied here as well since I can get neither of your examples to work and I'm kinda stuck at the moment: https://github.com/bpampuch/pdfmake/issues/150 – Berco Beute Feb 19 '16 at 16:37
  • I get "Module not found: Error: Can't resolve 'script'" when I use this require – Ioannis Tsiokos Jul 01 '19 at 10:51
  • did you install the webpack script loader? – circy Jul 10 '19 at 09:10