Answer the question
In order to leave comments, you need to log in
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
<!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>
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 );
})
})
{
"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"
}
}
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
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 questionAsk a Question
731 491 924 answers to any question