Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac conversion not working #59

Closed
gerhardcit opened this issue Apr 23, 2017 · 8 comments
Closed

Mac conversion not working #59

gerhardcit opened this issue Apr 23, 2017 · 8 comments

Comments

@gerhardcit
Copy link

macOS Sierra 10.12.3
node 6.9.1
phantomjs: 2.1.1

var app = express();

app.get('/', function (req, res) {
    var conversion = require("phantom-html-to-pdf")({
        timeout: 5000
    });

    conversion({ html: "<h1>Hello World</h1>" }, function (err, pdf) {
        if (err) {
            console.log(err);
            res.status(200).send(err);
        } else {
            console.log(pdf.logs);
            console.log(pdf.numberOfPages);
            pdf.stream.pipe(res);
        }
    });
});

result

{ Error: connect ECONNREFUSED 127.0.0.1:56033
    at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 56033 }

And the port number keeps changing?
Any help on that please?

@pofider
Copy link
Owner

pofider commented Apr 23, 2017

Can you try to use dedicated-process strategy?
https://github.com/pofider/phantom-html-to-pdf#global-options

Also, please try to find the phantomjs executable in node_modules and run it. Does it start?

@gerhardcit
Copy link
Author

I also solved it by doing this
npm install phantomjs-prebuilt
and then

var conversion = require("phantom-html-to-pdf")({
        phantomPath: require("phantomjs-prebuilt").path, 
        timeout: 5000
    });

but if I deploy to Ubuntu will this still work?

@pofider
Copy link
Owner

pofider commented Apr 23, 2017

It should.

@gerhardcit
Copy link
Author

@pofider
Running this on ubuntu 16.04
node 6.10.2

package.json contains

   "phantom-html-to-pdf": "^0.5.0",
   "phantomjs-prebuilt": "^2.1.14",

Init code

var conversion = require("phantom-html-to-pdf")({
    phantomPath: require("phantomjs-prebuilt").path
});

I'm using phantomPath because on mac that's the only way for it to work as mentioned above.

exec code

 conversion({
                html: htmlText,
                footer: '<div style="text-align:center">{#pageNum}/{#numPages}</div>',
                paperSize: {
                    format: 'A4',
                    orientation: 'portrait',
                    margin: '1cm'
                }
            }, function (err, pdf) {
                if (err) {
                   console.log(err)
                    cb(err);
                }
                else {
                    console.log(pdf.logs);
                    console.log(pdf.numberOfPages);
                    cb(null, pdf);
                }
            });

getting this error

 ERROR | UNCAUGHT | Sun Apr 23 2017 21:46:26 GMT+0000 (UTC) | TypeError: Bad argument
  at TypeError (native)
  at ChildProcess.spawn (internal/child_process.js:294:26)
  at ChildProcess.spawn (/usr/lib/node_modules/pm2/node_modules/async-listener/index.js:120:29)
  at exports.spawn (child_process.js:378:9)
  at Object.exports.execFile (child_process.js:143:15)
  at /home/ubuntu/apps/theapp-api/node_modules/phantom-workers/lib/phantomWorker.js:92:43
  at Server.<anonymous> (/home/ubuntu/apps/theapp-api/node_modules/phantom-workers/lib/phantomWorker.js:17:9)
   at emitNone (events.js:86:13)
  at Server.emit (events.js:185:7)
  at emitCloseNT (net.js:1558:8)

$ phantomjs -v
produces this:

Fontconfig warning: ignoring UTF-8: not a valid region tag
1.9.8

Anything you can possible help me with?

@pofider
Copy link
Owner

pofider commented Apr 24, 2017

Try to run this

apt-get install -y libfontconfig1 libfontconfig1-dev

We use this dockerfile to run this package on ubuntu https://github.com/jsreportonline/phantom-pdf/blob/master/Dockerfile
Just that it could help you to look inside.

@gerhardcit
Copy link
Author

@pofider here is a basic test. That I cannot get running on a basic machine fresh after setup.
https://github.com/gerhardcit/phantom-html-to-pdf-test

Would one expect that to work on a fresh Ubuntu machine setup?
Is there something about phantomjs that I don't know about?

@gerhardcit
Copy link
Author

@pofider, I tested that on a clean Ubuntu server.. just node and nginx.. perfect..
But not on the dev mac..
So what is compatibility with prebuilt about?

This pops up on mac with same node version

ERROR | UNCAUGHT | Mon Apr 24 2017 22:12:36 GMT+0200 (SAST) | TypeError: Bad argument
    at TypeError (native)
    at ChildProcess.spawn (internal/child_process.js:289:26)
    at exports.spawn (child_process.js:380:9)
    at Object.exports.execFile (child_process.js:143:15)
    at /Users/gerhard/Documents/projects/dev/phantom-test/node_modules/phantom-workers/lib/phantomWorker.js:92:43
    at Server.<anonymous> (/Users/gerhard/Documents/projects/dev/phantom-test/node_modules/phantom-workers/lib/phantomWorker.js:17:9)
    at emitNone (events.js:86:13)
    at Server.emit (events.js:185:7)
    at emitCloseNT (net.js:1553:8)
    at _combinedTickCallback (internal/process/next_tick.js:71:11)

@gerhardcit
Copy link
Author

@pofider , signing this off.
I had experimented with html5-to-pdf which uses electron, and that did not go well.
So after all that, this is a config that works.

"dependencies": {
    "express": "^4.15.2",
    "phantom-html-to-pdf": "^0.5.0",
    "phantomjs-prebuilt": "^2.1.14"
  }

and

var conversion = require("phantom-html-to-pdf")({
    phantomPath: require("phantomjs-prebuilt").path
});

on Development Mac and on Ubuntu 16.04
Closing this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants