일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 이더리움
- review
- Linux
- 스마트 컨트랙트
- 쿠버네티스
- 스마트 계약
- 암호화폐
- 시장
- Docker
- Games
- ps4
- loopback
- PC
- 탈중앙화
- game
- strongloop
- Three
- 리뷰
- 주식
- threejs
- 젤다 왕눈
- 투자
- kubernetes
- angular
- 부동산
- 게임
- 비트코인
- 보안
- 블록체인
- 거래
- Today
- Total
BaeBox
HTML 을 PDF, PPT, Word 로 export 하는 방법 본문

많은 방법이 있겠지만, 내가 소개하는 방법은 기본적으로 html2canvas를 이용하는 것이다.
html2cavnas : selector로 집어온 html을 base64 포맷의 이미지로 만들어주는 기능을 제공한다.
base64화된 이미지를 그대로 PDF, PPT, Word로 export해주는 툴에 붙여 넣으면 된다. 참 쉽죠?
이미지에 한해서는 이런 방식으로 해결이 가능하다. 사실 이미지 넣는게 가장 어려웠는데... ㅎㅎ;;
그 외의 것들은 공식문서에 다 친절히 나와있더라.
아래 소스코드의 canvas.toDataURL('image/png') 라는 코드는 base64를 반환한다.



생각보다는 내용이 간단하게 끝났다. 다행이다.
이주가량 붙잡고 있던 내용인데 헣... 뭔가 기분이 묘하다.
이 글을 보는 누군가에게 도움이 되었으면 좋겠다.
덤. 개발 환경에서는 아무 문제가 없다가 실제 서버에서 빌드 문제가 생긴 적이 있었는데, jszip이 문제를 일으켰었다. 아래 코드를 추가해주면 문제없이 잘 동작한다. 단 경우에 따라 jszip.min.js 인 경우도 있는 모양이더라. node_modules/jszip의 dist 디렉토리를 잘 확인해보자.

https://html2canvas.hertzen.com/
html2canvas - Screenshots with JavaScript
Try out html2canvas Test out html2canvas by rendering the viewport from the current page. Capture
html2canvas.hertzen.com
http://html2canvas.hertzen.com/documentation/
About - html2canvas
Before you get started with the script, there are a few things that are good to know regarding the script and some of its limitations. Introduction The script allows you to take "screenshots" of webpages or parts of it, directly on the users browser. The s
html2canvas.hertzen.com
https://github.com/mrrio/jspdf
MrRio/jsPDF
Client-side JavaScript PDF generation for everyone. - MrRio/jsPDF
github.com
docx - Generate .docx documents with JavaScript
docx.js.org
https://gitbrent.github.io/PptxGenJS/
PptxGenJS · JavaScript library that creates PowerPoint presentations
JavaScript library that creates PowerPoint presentations
gitbrent.github.io
'개발 관련' 카테고리의 다른 글
Node - Cluster Module (0) | 2020.03.14 |
---|---|
자바스크립트는 어떻게 동작하는가 시리즈.(펌) (0) | 2020.03.13 |
Dynamic(동적) Component 생성 (0) | 2020.03.02 |
Component간 데이터 공유 (0) | 2020.03.02 |
Scapy를 이용한 packet(pcap) generation (0) | 2020.02.09 |