Работаю в Node.js, PostgreSQL,Express.
Пытаюсь скачать PDF-файл со своего localhost. Вроде бы файл скачивает и открывается без проблем, но он понимает только латиницу, а если добавить данные кириллицы он будет его писать какими-то символами. Такой вопрос как сделать, чтобы понимало кириллицу ?
Использую пакет pdfkit
.
const pdf = require('pdfkit');
var myDoc = new pdf;
const download1 =(req,res) => {
const db = new pg.Pool(admin_role.client_admin)
db.connect(function(err, client, done){
console.log("admin")
if(err){
return console.error('Соединение не удалось')
}
client.query(admin_role.accounting_wokr_transport, function(err, result1){
if (err){
res.end()
return console.error("Запрос не удался")
}
done()
console.log(result1);
myDoc.pipe(fs.createWriteStream( '12345.pdf')); //creates pdf with the name of the user
var print=0;
myDoc.font('Helvetica');
myDoc.fontSize(30);
myDoc.text('Dear ' + 'Marina' + ',' , 50 , 50 );
myDoc.fontSize(20);
myDoc.text(' ');
myDoc.text('You have paid an amount of INR ' + 1111 + '/- to our organisation.' );
myDoc.fontSize(15);
myDoc.fillColor('red');
myDoc.text('This money will be used by us to provide free eduction to the poor children.');
myDoc.text(' ');
myDoc.fillColor('green');
myDoc.text('Your contribution will be remembered and recognised, as of the following other donors:');
var k=1;
console.table(result1.rows[0].address)
myDoc.text('почему не понимаешь кириллицу ?',{lang:'ru'});
setTimeout(function(){ var data =fs.readFileSync('./'+ '12345.pdf', {root: __dirname});
res.contentType("application/pdf");
res.send(data);
end=1;
},3000);
setTimeout( function(){res.end();}, 7000);
// res.download('/12345.pdf')
myDoc.end();
})
})
}
app.post('/accounting_download',urlencodedParser,db_admin.download1)