html-to-pdf : https://github.com/ChaosEvoker/html-to-pdf
다음과 같이 HTML을 PDF로 변환하고 싶습니다.
var htmlToPdf = require('html-to-pdf');
var html = '<div>test</div>'; //Some HTML String from code above
htmlToPdf.convertHTMLString(html, '.\\pdf\\thepdf.pdf',
function (error, success) {
if (error) {
console.log('Oh noes! Errorz!');
console.log(error);
} else {
console.log('Woot! Success!');
console.log(success);
}
}
);
콘솔 :
Woot! Success!
{ process_code: 1 }
성공했지만. \ pdf 또는 다른 곳에서 "thepdf.pdf"를 찾을 수 없습니다.
npm 모듈 html-pdf 사용
var fs = require('fs');
var pdf = require('html-pdf');
var html = fs.readFileSync('./home.html', 'utf8'); //to your html file
var options = { format: 'Letter' };
//in your case just your html code in place of html
//pdf.create(<html><div>test</div></html>,.....)
pdf.create(html, options).toFile('./gerrateddoc.pdf', function(err, res) {
if (err) return console.log(err);
console.log(res); // { filename: '/genrateddoc.pdf' }
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다