티스토리 뷰
반응형
[javascript(node)]html to pdf / pdf파일 생성하기
node(javascript)환경에서 phantom 라이브러리를 통해 손쉽게 pdf 파일을 생성할 수 있다.
[공식 npm 페이지]
https://www.npmjs.com/package/phantom
phantom
PhantomJS integration module for NodeJS
www.npmjs.com
[설치 방법]
npm i phantom
[코드]
var phantom = require("phantom");
phantom.create().then(function (ph) {
ph.createPage().then(function (page) {
page
.open(
"url"
)
.then(function (status) {
page.render("test.pdf").then(function () {
console.log("Page Rendered");
ph.exit();
});
});
});
});
"url" 부분에 원하는 페이지를 넣고 실행하면 pdf파일이 생성된다.
#phantom #code #js #javascript #pdf #htmltopdf #html #pdf파일생성 #pdf만들기
반응형
'자바스크립트(javascript)' 카테고리의 다른 글
[node/js] node에서 간단한 udp server / client 구현 (0) | 2021.12.11 |
---|---|
[node/js] node환경에서 import 쓰기(es6) (0) | 2021.12.11 |
[nestjs/typeorm]typeormmodule unable to connect to the database queryfailerror null column 오류 발생 시 column추가하여 실행 시 오류 (0) | 2021.11.22 |
[nodejs(노드)/npm] 설치 (0) | 2021.11.12 |
[node(노드)/express(익스프레스)] 1분만에 API 서버 만들기 (0) | 2021.11.11 |
댓글
반응형