authscape 1.0.158 → 1.0.159
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +41 -25
- package/package.json +1 -1
- package/src/components/pageToPDF.js +50 -26
package/index.js
CHANGED
|
@@ -1140,34 +1140,50 @@ var PageToPDF = function PageToPDF(_ref) {
|
|
|
1140
1140
|
elementById = _ref.elementById,
|
|
1141
1141
|
_ref$scale = _ref.scale,
|
|
1142
1142
|
scale = _ref$scale === void 0 ? 2 : _ref$scale,
|
|
1143
|
-
_ref$
|
|
1144
|
-
|
|
1143
|
+
_ref$showHideClassEle = _ref.showHideClassElements,
|
|
1144
|
+
showHideClassElements = _ref$showHideClassEle === void 0 ? [] : _ref$showHideClassEle,
|
|
1145
1145
|
_ref$fileName = _ref.fileName,
|
|
1146
1146
|
fileName = _ref$fileName === void 0 ? "download" : _ref$fileName;
|
|
1147
|
+
var onHideElements = function onHideElements() {
|
|
1148
|
+
for (var index = 0; index < showHideClassElements.length; index++) {
|
|
1149
|
+
var element = showHideClassElements[index];
|
|
1150
|
+
var className = document.getElementsByClassName(element);
|
|
1151
|
+
if (className != null) {
|
|
1152
|
+
className.style.display = "none";
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
};
|
|
1156
|
+
var onShowElements = function onShowElements() {
|
|
1157
|
+
for (var index = 0; index < showHideClassElements.length; index++) {
|
|
1158
|
+
var element = showHideClassElements[index];
|
|
1159
|
+
var className = document.getElementsByClassName(element);
|
|
1160
|
+
if (className != null) {
|
|
1161
|
+
className.style.display = "block";
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1147
1165
|
var printElement = function printElement() {
|
|
1148
|
-
onHideElements(
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
}, 2000);
|
|
1170
|
-
onHideElements(false);
|
|
1166
|
+
onHideElements();
|
|
1167
|
+
var input = document.getElementById(elementById);
|
|
1168
|
+
(0, _html2canvas["default"])(input, {
|
|
1169
|
+
backgroundColor: null,
|
|
1170
|
+
scale: scale
|
|
1171
|
+
}).then(function (canvas) {
|
|
1172
|
+
var imgData = canvas.toDataURL("image/png", 1.0);
|
|
1173
|
+
var pdf = new _jspdf.jsPDF();
|
|
1174
|
+
var pdfWidth = pdf.internal.pageSize.getWidth();
|
|
1175
|
+
var pdfHeight = pdf.internal.pageSize.getHeight();
|
|
1176
|
+
var imgWidth = canvas.width;
|
|
1177
|
+
var imgHeight = canvas.height;
|
|
1178
|
+
var scaleFactor = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight);
|
|
1179
|
+
var scaledWidth = imgWidth * scaleFactor;
|
|
1180
|
+
var scaledHeight = imgHeight * scaleFactor;
|
|
1181
|
+
var x = (pdfWidth - scaledWidth) / 2;
|
|
1182
|
+
var y = 0; // Set y coordinate to 0 to align to the top
|
|
1183
|
+
pdf.addImage(imgData, "PNG", x, y, scaledWidth, scaledHeight);
|
|
1184
|
+
pdf.save(fileName + ".pdf");
|
|
1185
|
+
});
|
|
1186
|
+
onShowElements();
|
|
1171
1187
|
};
|
|
1172
1188
|
return /*#__PURE__*/_react["default"].createElement(_Box["default"], null, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
|
|
1173
1189
|
startIcon: startIcon,
|
package/package.json
CHANGED
|
@@ -5,35 +5,59 @@ import { jsPDF } from "jspdf";
|
|
|
5
5
|
import Button from "@mui/material/Button";
|
|
6
6
|
import DownloadRoundedIcon from '@mui/icons-material/DownloadRounded';
|
|
7
7
|
|
|
8
|
-
export const PageToPDF = ({buttonText = "Download", startIcon = <DownloadRoundedIcon/>, variant = "contained", elementById, scale = 2,
|
|
8
|
+
export const PageToPDF = ({buttonText = "Download", startIcon = <DownloadRoundedIcon/>, variant = "contained", elementById, scale = 2, showHideClassElements = [], fileName = "download"}) => {
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const onHideElements = () => {
|
|
12
|
+
|
|
13
|
+
for (let index = 0; index < showHideClassElements.length; index++) {
|
|
14
|
+
const element = showHideClassElements[index];
|
|
15
|
+
|
|
16
|
+
let className = document.getElementsByClassName(element);
|
|
17
|
+
if (className != null)
|
|
18
|
+
{
|
|
19
|
+
className.style.display = "none";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const onShowElements = () => {
|
|
25
|
+
|
|
26
|
+
for (let index = 0; index < showHideClassElements.length; index++) {
|
|
27
|
+
const element = showHideClassElements[index];
|
|
28
|
+
|
|
29
|
+
let className = document.getElementsByClassName(element);
|
|
30
|
+
if (className != null)
|
|
31
|
+
{
|
|
32
|
+
className.style.display = "block";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
9
37
|
|
|
10
38
|
const printElement = () => {
|
|
11
39
|
|
|
12
|
-
onHideElements(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}, 2000);
|
|
35
|
-
|
|
36
|
-
onHideElements(false);
|
|
40
|
+
onHideElements();
|
|
41
|
+
|
|
42
|
+
const input = document.getElementById(elementById);
|
|
43
|
+
html2canvas(input, {backgroundColor: null, scale: scale})
|
|
44
|
+
.then((canvas) => {
|
|
45
|
+
const imgData = canvas.toDataURL("image/png", 1.0);
|
|
46
|
+
const pdf = new jsPDF();
|
|
47
|
+
const pdfWidth = pdf.internal.pageSize.getWidth();
|
|
48
|
+
const pdfHeight = pdf.internal.pageSize.getHeight();
|
|
49
|
+
const imgWidth = canvas.width;
|
|
50
|
+
const imgHeight = canvas.height;
|
|
51
|
+
const scaleFactor = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight);
|
|
52
|
+
const scaledWidth = imgWidth * scaleFactor;
|
|
53
|
+
const scaledHeight = imgHeight * scaleFactor;
|
|
54
|
+
const x = (pdfWidth - scaledWidth) / 2;
|
|
55
|
+
const y = 0; // Set y coordinate to 0 to align to the top
|
|
56
|
+
pdf.addImage(imgData, "PNG", x, y, scaledWidth, scaledHeight);
|
|
57
|
+
pdf.save(fileName + ".pdf");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
onShowElements();
|
|
37
61
|
}
|
|
38
62
|
|
|
39
63
|
|