<p>html2canvas๊ฐ€ ์ „์ฒด ํ™”๋ฉด์„ ์บก์ฒ˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. (๊ทธ๋ฆฌ์Šคํ„ฐ 2)</p>

์— ๋งŒ๋“  2018๋…„ 12์›” 12์ผ  ยท  4์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: niklasvh/html2canvas

์•ˆ๋…•
html2canvas๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋ฉฐ ๋‚ด ํŽ˜์ด์ง€์—๋Š” gridster ์œ„์ ฏ์ด ์žˆ๊ณ  ๊ฐ ์œ„์ ฏ์—๋Š” ๋ณด๊ณ ์„œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์บ”๋ฒ„์Šค๋ฅผ ์ค€๋น„ํ•˜๋ ค๊ณ  ํ•  ๋•Œ ํŽ˜์ด์ง€์˜ ๋ชจ๋“  ํ•ญ๋ชฉ์„ ์บก์ฒ˜ํ•  ์ˆ˜ ์—†์œผ๋ฉฐ ๋ณด์ด๋Š” ์˜์—ญ์— ์™„์ „ํžˆ ์žˆ๋Š” ํ•ญ๋ชฉ๋„ ์บก์ฒ˜ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

print(element: Element, renderer: Renderer2, includeSvgs = true) {
        const height = element.clientHeight;
        const width = element.clientWidth;
        if (includeSvgs) {
            this.convertSvgElems(element, renderer);
        }
        html2canvas(element).then((canvas) => {
            let html = '<html><head><title></title></head>';
            html += '<body style="width:"' + width + '" ;height:"' + height + '" padding: 0; margin: 0;"';
            html += ' onload="window.focus(); window.print(); window.close()">';
            html += '<img crossorigin="anonymous" allowTaint = true useCORS=true src="' + canvas.toDataURL() + '" /></body></html>';
            const printWindow = window.open('', 'to_print', 'height=700,width=800');
            printWindow.document.open();
            printWindow.document.write(html);
            if (includeSvgs) {
                this.deleteCanvasElems(element, renderer);
            }
            printWindow.document.close();
        });

    }

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

์ „ํ™˜์„ ์ œ๊ฑฐํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.
์ „์—ญ ๋ฒ”์œ„์— ๋‹ค์Œ CSS ๊ทœ์น™์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

  .gridster-item {
        transition: unset !important;
    }

๋ชจ๋“  4 ๋Œ“๊ธ€

๋น„์Šทํ•œ ๋ฌธ์ œ๊ฐ€ ์–ธ๊ธ‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค
์—ฌ๊ธฐ

์—…๋ฐ์ดํŠธ: ๋ธŒ๋ผ์šฐ์ € ์ฝ˜์†”์„ ํ†ตํ•ด ๋™์ผํ•œ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ฒฝ์šฐ ์™„๋ฒฝํ•˜๊ฒŒ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. ๋‘ ๊ฐ€์ง€ ๋ชจ๋‘์— ๋Œ€ํ•ด ์•„๋ž˜ ์–ธ๊ธ‰๋œ ๋กœ๊ทธ๋ฅผ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค.

์ฝ˜์†”์„ ํ†ตํ•ด:

ZoneAwarePromiseย {__zone_symbol__state: null, __zone_symbol__value: Array(0)}
jspdf.min.js:5422 495ms html2canvas: Document cloned
jspdf.min.js:5422 497ms html2canvas: Initialized CanvasRenderer with size 1366 x 622
jspdf.min.js:5422 497ms html2canvas: Starting NodeParser
jspdf.min.js:5422 635ms html2canvas: Fetched nodes, total: 2104
jspdf.min.js:5422 636ms html2canvas: Calculate overflow clips
jspdf.min.js:5422 1030ms html2canvas: Start fetching images
jspdf.min.js:5422 1034ms html2canvas: Added image #1 <svg xmlns:xlink=โ€‹"http:โ€‹/โ€‹/โ€‹www.w3.org/โ€‹1999/โ€‹xlink" height=โ€‹"24px" version=โ€‹"1.1" viewBox=โ€‹"0 0 24 24" width=โ€‹"24px" xmlns=โ€‹"http:โ€‹/โ€‹/โ€‹www.w3.org/โ€‹2000/โ€‹svg">โ€‹โ€ฆโ€‹</svg>โ€‹
jspdf.min.js:5422 1037ms html2canvas: Added image #2 <svg xmlns:xlink=โ€‹"http:โ€‹/โ€‹/โ€‹www.w3.org/โ€‹1999/โ€‹xlink" height=โ€‹"24px" version=โ€‹"1.1" viewBox=โ€‹"0 0 24 24" width=โ€‹"24px" xmlns=โ€‹"http:โ€‹/โ€‹/โ€‹www.w3.org/โ€‹2000/โ€‹svg">โ€‹โ€ฆโ€‹</svg>โ€‹
jspdf.min.js:5422 1040ms html2canvas: Added image #3 <svg xmlns:xlink=โ€‹"http:โ€‹/โ€‹/โ€‹www.w3.org/โ€‹1999/โ€‹xlink" height=โ€‹"24px" version=โ€‹"1.1" viewBox=โ€‹"0 0 24 24" width=โ€‹"24px" xmlns=โ€‹"http:โ€‹/โ€‹/โ€‹www.w3.org/โ€‹2000/โ€‹svg">โ€‹โ€ฆโ€‹</svg>โ€‹
jspdf.min.js:5422 1040ms html2canvas: Added image #4 <svg xmlns:xlink=โ€‹"http:โ€‹/โ€‹/โ€‹www.w3.org/โ€‹1999/โ€‹xlink" height=โ€‹"24px" version=โ€‹"1.1" viewBox=โ€‹"0 0 24 24" width=โ€‹"24px" xmlns=โ€‹"http:โ€‹/โ€‹/โ€‹www.w3.org/โ€‹2000/โ€‹svg">โ€‹โ€ฆโ€‹</svg>โ€‹
jspdf.min.js:5422 1042ms html2canvas: Added image #5 <svg xmlns:xlink=โ€‹"http:โ€‹/โ€‹/โ€‹www.w3.org/โ€‹1999/โ€‹xlink" height=โ€‹"24px" version=โ€‹"1.1" viewBox=โ€‹"0 0 24 24" width=โ€‹"24px" xmlns=โ€‹"http:โ€‹/โ€‹/โ€‹www.w3.org/โ€‹2000/โ€‹svg">โ€‹โ€ฆโ€‹</svg>โ€‹
jspdf.min.js:5422 1053ms html2canvas: Finished searching images
jspdf.min.js:5422 1063ms html2canvas: Succesfully loaded image #5 rย {src: svg, image: img, promise: ZoneAwarePromise}
jspdf.min.js:5422 1065ms html2canvas: Succesfully loaded image #4 rย {src: svg, image: img, promise: ZoneAwarePromise}
jspdf.min.js:5422 1067ms html2canvas: Succesfully loaded image #3 rย {src: svg, image: img, promise: ZoneAwarePromise}
jspdf.min.js:5422 1068ms html2canvas: Succesfully loaded image #2 rย {src: svg, image: img, promise: ZoneAwarePromise}
jspdf.min.js:5422 1069ms html2canvas: Succesfully loaded image #1 rย {src: svg, image: img, promise: ZoneAwarePromise}
jspdf.min.js:5422 1071ms html2canvas: Images loaded, starting parsing
jspdf.min.js:5422 1072ms html2canvas: Creating stacking contexts
jspdf.min.js:5422 1110ms html2canvas: Sorting stacking contexts
jspdf.min.js:5422 1138ms html2canvas: Render queue created with 3026 items
jspdf.min.js:5422 3316ms html2canvas: Finished rendering
jspdf.min.js:5422 3328ms html2canvas: Cropping canvas at: left: 0 top: 61 width: 1366 height: 561
jspdf.min.js:5422 3340ms html2canvas: Resulting crop with width 1366 and height 561 with x 0 and y 61
jspdf.min.js:5422 3388ms html2canvas: Cleaned up container

์ฝ”๋“œ๋ฅผ ํ†ตํ•ด:

0ms html2canvas: html2canvas $npm_package_version
Logger.js:36 1028ms html2canvas: Document cloned, using computed rendering
Logger.js:36 1028ms html2canvas: Starting node parsing
Logger.js:36 1096ms html2canvas: Added image data:image/svg+xml,%3Csvg%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20height%3D%2224px%22%20version%3D%221.1%22%20viewBox%3D%220%200%2024%2024%22%20width%3D%2224px%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20style%3D%22di
Logger.js:36 1359ms html2canvas: Finished parsing node tree
Logger.js:36 1496ms html2canvas: Finished loading 11 images (11)ย [canvas.screenShotTempCanvas, canvas, canvas.screenShotTempCanvas, canvas, canvas.screenShotTempCanvas, canvas, canvas.screenShotTempCanvas, canvas, canvas.screenShotTempCanvas, canvas, img]
Logger.js:36 1497ms html2canvas: Starting renderer
Logger.js:36 1498ms html2canvas: Canvas renderer initialized (1366x561 at 0,61) with scale 1
Logger.js:36 1599ms html2canvas: Render completed

๋‘ ๊ฒฝ์šฐ ๋ชจ๋‘์— ๋Œ€ํ•œ ์ด๋ฏธ์ง€๋„ ์ฒจ๋ถ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

not-working
working

์—…๋ฐ์ดํŠธํ•˜์‹ญ์‹œ์˜ค.
๊ฐ์‚ฌ ํ•ด์š”

์ „ํ™˜์„ ์ œ๊ฑฐํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.
์ „์—ญ ๋ฒ”์œ„์— ๋‹ค์Œ CSS ๊ทœ์น™์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

  .gridster-item {
        transition: unset !important;
    }

gridster๊ฐ€ ํƒœ๊ทธ์ธ ๊ฒฝ์šฐ Angular ํ”„๋กœ์ ํŠธ์—์„œ. ์ „์—ญ scss์— ๋‹ค์Œ ์ถ”๊ฐ€

gridster-item {
  transition: unset !important;
}
์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰