0

Here are the relevant code.

        let Name = moment().unix() + ".pdf";
        var html = fs.readFileSync('./test/businesscard.html', 'utf8');
        let filename = "C:\\App\\Register\\pdf\\" + Name;
        pdf.create(html, options).toFile(filename, function (err, response) {
          if (err) {
             res.status(403).json({
               message: 'error'
             })
           } else {
              res.status(200).json({
               message: 'success'
             })

           }
    }

it's working fine on dev version and create PDF file. But when i create a electron build-pack, the pdf file not generated.

If any solution is available then it will be a big help

Ali Raza
  • 83
  • 1
  • 11

1 Answers1

1

You should use an absolute path for packaged application by using app.getAppPath().

Remplace this line

var html = fs.readFileSync('./test/businesscard.html', 'utf8');

By this

var html = fs.readFileSync(path.join(app.getAppPath(), '/test/businesscard.html', 'utf8'));

And not forgot to add

const path = require('path')
const app = require('electron').remote.app
popod
  • 397
  • 3
  • 10
  • i already try to solve to place html in the same block of code before the pdf.create(html, options) but still the same error.. – Ali Raza Apr 18 '19 at 10:02