Skip to content

Commit e22bb2a

Browse files
committed
Improvement - Add html2canvas options to composables and config
1 parent 5dcc42b commit e22bb2a

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

src/img.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import html2canvas from 'html2canvas';
22

3-
export default function saveAsImage({ domElement, fileName, format = 'png' }) {
3+
export default function saveAsImage({ domElement, fileName, format = 'png', options = {} }) {
44
if (domElement) {
55
return new Promise((resolve, reject) => {
66
const downloadLink = document.createElement('a');
7-
html2canvas(domElement, { scale: 2 })
7+
html2canvas(domElement, { ...options })
88
.then((canvas) => {
99
downloadLink.href = canvas.toDataURL(`image/${format}`);
1010
downloadLink.download = `${fileName}.${format}`;

src/pdf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import html2canvas from 'html2canvas';
22
import JsPDF from "jspdf";
33

4-
export default function pdf({domElement, fileName}) {
4+
export default function pdf({domElement, fileName, options = {} }) {
55
if(domElement) {
66
const a4 = {
77
height: 851.89,
88
width: 595.28,
99
};
1010
const pdf = new JsPDF("", "pt", "a4");
1111
let contentWidth, contentHeight, imgWidth, imgHeight, pageData;
12-
return html2canvas(domElement)
12+
return html2canvas(domElement, { ...options })
1313
.then((canvasChart) => {
1414
contentWidth = canvasChart.width;
1515
contentHeight = canvasChart.height;

src/useConfig.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,15 @@ export function useConfig() {
171171
animation,
172172
annotator
173173
},
174-
buttonTitles
174+
buttonTitles,
175+
// html2canvas options
176+
print: {
177+
allowTaint: false,
178+
backgroundColor: '#FFFFFF',
179+
useCORS: false,
180+
onclone: null,
181+
scale: 2
182+
}
175183
}
176184
}
177185

@@ -2491,6 +2499,13 @@ export function useConfig() {
24912499
fullscreen: 'Toggle fullscreen',
24922500
annotator: 'Toggle annotator'
24932501
},
2502+
userOptionsPrint: {
2503+
allowTaint: false,
2504+
backgroundColor: '#FFFFFF',
2505+
useCORS: false,
2506+
onclone: null,
2507+
scale: 2
2508+
},
24942509
title: '',
24952510
titleBold: true,
24962511
titleFontSize: FONT._16,

src/usePrinter.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { ref } from "vue";
33
export function usePrinter({
44
elementId,
55
fileName,
6-
canPrint = true
6+
canPrint = true,
7+
options
78
}) {
89
const isPrinting = ref(false);
910
const isImaging = ref(false);
@@ -20,6 +21,7 @@ export function usePrinter({
2021
await pdf({
2122
domElement: document.getElementById(elementId),
2223
fileName,
24+
options
2325
});
2426
} catch (error) {
2527
console.error("Error generating PDF:", error);
@@ -42,6 +44,7 @@ export function usePrinter({
4244
domElement: document.getElementById(elementId),
4345
fileName,
4446
format: "png",
47+
options
4548
});
4649
} catch (error) {
4750
console.error("Error generating image:", error);

0 commit comments

Comments
 (0)