mrafiqk/html-pdf-node

Error: connect ECONNREFUSED 127.0.0.1:80

Opened this issue · 6 comments

This my code
`
try {
let html = await creator.html(document, options);
//save to file then email it
console.log("try")
let file = { content: html};
console.log(html)
//file = { url: "https://example.com" };

    console.log(file)
    html_to_pdf.generatePdf(file, options).then(output => {
        console.log("PDF Buffer:-", output); // PDF Buffer:- [{url: "https://example.com", name: "example.pdf", buffer: <PDF buffer>}]
    });
    /*
    html_to_pdf.generatePdf(file, options).then(pdfBuffer => {
        io.to(res.locals.token).emit("message", data.title +  " has been created");
        res.header('Content-type', 'application/pdf')
        res.send(pdfBuffer)
    });*/
} catch (err) {
    console.log(err);
    io.to(res.locals.token).emit("error", data.title +  " error " + err.toString());
    debug(req, res, err);
    res.json(err.toString())
}

`

and error using file content

node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^

Error: connect ECONNREFUSED 127.0.0.1:80
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 80,
response: undefined
}
[nodemon] app crashed - waiting for file changes before starting...

Same issue

I was having this issue but this seems to work:
try { let file = {content: bdy.html}; let pdfBuffer = await html_to_pdf.generatePdf(file, pdfOpts); const stream = Readable.from(pdfBuffer); res.set('Content-Type', 'application/pdf'); stream.pipe(res); // console.log("PDF Buffer:-", pdfBuffer); } catch (error) { console.error(new Date().toLocaleString() + " ERROR: " + error); }

I faced this issue too. I did some experiment and realised it works when removed all external file reference. e.g.

<html>
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
...
</body>
</html>

Remove <link rel="stylesheet" type="text/css" href="style.css" />. The PDF generated successfully.

Yeah, but if you will publish yoour project it will be failed, at least it was in my case

you need to fully qualify the href value for your style sheet to make it work
eg:
<link rel='stylesheet' media="print" href='http://localhost:3017/stylesheets/reportStyles.css'/>

you also need to do this for images in the img tag.
the src attribute in the script tag also needs to be fully qualified for them to be included

i am facing same issue and tried all the approach which is given above but not able to fix the error .
when i send simple html from postman pdf get generated but when i copy the html from inspect "of that page which page padf i need" and post it throught postman "Terror": "connect ECONNREFUSED 127.0.0.1:80" this error come
please help!