728x90
특정 div 일부만 이미지로 저장하고 싶다면 html2cnvas 스크립트로 가능하다. pdf 로 다운로드는 구현이 조금 까다롭지만 스크립트로는 아래와 같이 코드 몇줄만 적으면 다운로드 파일 이름도 정의할 수 있고 jpg 파일로 저장 할수 있다.
<div class="com_btn_wrap right">
<button class="com_btn l point btn_download" type="button" onclick="downloadImage()"><i class="icon svg_icon before icon_download white"></i>다운로드</button>
</div>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<script>
function downloadImage() {
// Get the target div
var divToCapture = document.getElementById('mindScoreBody');
// Use html2canvas to capture the div as an image
html2canvas(divToCapture).then(function (canvas) {
// Convert the canvas to a data URL
var imageData = canvas.toDataURL('image/jpeg');
// Create a link element and trigger a download
var link = document.createElement('a');
link.href = imageData;
link.download = 'output.jpg';
link.click();
});
}
</script>
728x90
'JAVASCRIPT' 카테고리의 다른 글
javascript 드래그로 첨부파일 구현 멀티 업로드 (0) | 2024.07.02 |
---|---|
canvas로 낙서장 만들기 스크립트 지우개 기능 추가 반응형 적용 (0) | 2024.06.12 |
동영상 재생 완료 후 스크립트 실행 예제 (0) | 2023.12.11 |
javscript 페이지 새로고침 param 까지 같이 이동 (0) | 2023.11.14 |
jquery 달력 스크립트 커스텀마이징 원하는 요일만 나오게 (0) | 2023.09.21 |