G
G
Galdar Turin2021-07-09 13:48:55
Node.js
Galdar Turin, 2021-07-09 13:48:55

How to fix HTML to PDF conversion error?

The error says that there is a problem with the path or with the file to which it writes, I checked the path many times, other functions for creating a file work and the converter from xls to pdf works the same, but why is there such an error in this library, who has encountered or knows how to solve, google but did not find the answer

html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= title %></title>
</head>
<body style="font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size:10px; padding:20px 40px; margin: 0; line-height:1.5;">
    
    <table cellspacing="0" cellpadding="0" width="100%">

        <tr>

            <% for( let i in column ){ %>
                <th><%- column[ i ] %></th>
            <% } %>
         
        </tr>

        <tr>

            <% for( let i in value ){ %>

                <% for( let v in value[ i ] ){ %>

                    <td><%- value[ i ][ v ] %></td>
                    
                <% } %>

            <% } %>

        </tr>

    </table>

</body>
</html>



The code

let params = {

        "title": fileName,
        "column": arrayColumn,
        "value": resultData["result"]

    }

    ejs.renderFile( manifest.file.templ.pdf, params, ( err, html ) => {

        if( err ) console.log( err );

        const options = { "format": "Letter"}

        console.log(`${timePath}${fileName}`);

        convert_HTML_PDF.create( html, options ).toFile( `${timePath}${fileName}`, (err, res) => {

            console.log(res);

            if( err ) console.log( err );

        })

    })



Mistake

Error: html-pdf: Unknown Error
Auto configuration failed
140068023615104:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:185:filename(libssl_conf.so): libssl_conf.so: cannot open shared object file: No such file or directory
140068023615104:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
140068023615104:error:0E07506E:configuration file routines:MODULE_LOAD_DSO:error loading dso:conf_mod.c:285:module=ssl_conf, path=ssl_conf
140068023615104:error:0E076071:configuration file routines:MODULE_RUN:unknown module name:conf_mod.c:222:module=ssl_conf

at ChildProcess.respond (/var/test/node_modules/html-pdf/lib/pdf.js:134:17)
at ChildProcess.emit (events.js:314:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)



After checking the library apart from the main project it works. So there are some problems with the libraries in the main project or in the structure itself, but what can interfere?

Now a clean project with two libraries for building a pdf file gives the same error. The server did not reboot, it just began to give an error from scratch, did not change anything. I think it's already a matter of server settings, but what, what's stopping you?
package.json

{
  "name": "html-pdf-converter",
  "version": "1.0.0",
  "description": "HTML to PDF converter",
  "main": "index.js",
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ejs": "2.5.7",
    "html-pdf": "^3.0.1"
  }
}



index

const http = require('http');
const fs = require('fs');
const port = 6006;
const htmlPdf = require('html-pdf');
const ejs = require('ejs');

const requestHandler = (request, response) => {

    if (request.url.indexOf('.') != -1){

        response.end(fs.readFileSync(__dirname + request.url));

    } else {

        let date = new Date();
        let month = date.getMonth() + 1;
        month = (month < 10 ? '0' + month : month);
        let day = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
        date = day + '.' + month + '.' + date.getFullYear();

        const params = {
            name: "Аида Дроган",
            email: "[email protected]",
            id: "127001",
            company: "#BlondieCode",
            logo: "/images/logo.png",
            date: date,
            quantity: 1,
            price: 66,
            currency: "BTC",
            product: "Вундер-Вафля (меч, серебро)",
            units: "штука"
        };

        ejs.renderFile(__dirname + '/template.ejs', params, (err, html) => {

            const options = { format: 'A4'};
            const fileName = __dirname + '/file.pdf';

            const renderHtml = html.replace(/img src=\"\//g, 'img src="file://' + __dirname + "/");

            htmlPdf.create(renderHtml, options).toFile(fileName, (err) => {

                if (err) {
                    console.log('Ошибка конвертации', err)
                }

                response.end(html);
            });

        })
    }

};

const server = http.createServer(requestHandler);

server.listen(port, (err) => {

    if (err) {
        return console.log('Ошибка сервера', err)
    }

    console.log(`Вишу на порту ${port}`);
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Galdar Turin, 2021-07-11
@Galdar

Temporary solution to the problem
https://github.com/bazelbuild/rules_closure/issues/351
Run in the project: export OPENSSL_CONF=/dev/null
This method is so-so, at the moment I noticed that this setting is reset and periodically it needs to be rewritten. If someone finds a better way, please post.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question