bpampuch / pdfmake

Client/server side PDF printing in pure JavaScript
http://pdfmake.org
Other
11.63k stars 2.04k forks source link

FS is Not Defined #1246

Closed chiaramdelucia closed 6 years ago

chiaramdelucia commented 6 years ago

Hello,

I'm currently trying to use PDFMake on the server side with Node.js. Unfortunately, I'm getting an error related to FS that is reading:

fs is not defined at Object.module.exports.fontkit.openSync

Below is my code:

const fs = require('fs');
const PdfPrinter = require('pdfmake/src/printer');
// The Roboto file is in the root of the application like others have mentioned to do
const fontDescriptors = {
        Roboto: {
          normal: './fonts/Roboto-Regular.ttf', 
          bold: './fonts/Roboto-Medium.ttf',
          italics: './fonts/Roboto-Italic.ttf',
          bolditalics: './fonts/Roboto-MediumItalic.ttf',
        },
 };
const printer = new PdfPrinter(fontDescriptors);
const pdfDoc = printer.createPdfKitDocument(reportDefinition);
pdfDoc.pipe(fs.createWriteStream('basics.pdf')).on('finish', function () {
        console.log('pdf success');
});
pdfDoc.end();

To note: I'm using this inside an Electron app, so the browser is Chromium.

Any help would be much appreciated.

Thank you.

liborm85 commented 6 years ago

Electron working on browser (not in server-side), you must use client-side version.