authscape 1.0.156 → 1.0.158
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 +25 -19
- package/package.json +1 -1
- package/src/components/pageToPDF.js +26 -18
package/index.js
CHANGED
|
@@ -1140,28 +1140,34 @@ 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$onHideElements = _ref.onHideElements,
|
|
1144
|
+
onHideElements = _ref$onHideElements === void 0 ? null : _ref$onHideElements,
|
|
1143
1145
|
_ref$fileName = _ref.fileName,
|
|
1144
1146
|
fileName = _ref$fileName === void 0 ? "download" : _ref$fileName;
|
|
1145
1147
|
var printElement = function printElement() {
|
|
1146
|
-
|
|
1147
|
-
(
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1148
|
+
onHideElements(true);
|
|
1149
|
+
setTimeout(function () {
|
|
1150
|
+
var input = document.getElementById(elementById);
|
|
1151
|
+
(0, _html2canvas["default"])(input, {
|
|
1152
|
+
backgroundColor: null,
|
|
1153
|
+
scale: scale
|
|
1154
|
+
}).then(function (canvas) {
|
|
1155
|
+
var imgData = canvas.toDataURL("image/png", 1.0);
|
|
1156
|
+
var pdf = new _jspdf.jsPDF();
|
|
1157
|
+
var pdfWidth = pdf.internal.pageSize.getWidth();
|
|
1158
|
+
var pdfHeight = pdf.internal.pageSize.getHeight();
|
|
1159
|
+
var imgWidth = canvas.width;
|
|
1160
|
+
var imgHeight = canvas.height;
|
|
1161
|
+
var scaleFactor = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight);
|
|
1162
|
+
var scaledWidth = imgWidth * scaleFactor;
|
|
1163
|
+
var scaledHeight = imgHeight * scaleFactor;
|
|
1164
|
+
var x = (pdfWidth - scaledWidth) / 2;
|
|
1165
|
+
var y = 0; // Set y coordinate to 0 to align to the top
|
|
1166
|
+
pdf.addImage(imgData, "PNG", x, y, scaledWidth, scaledHeight);
|
|
1167
|
+
pdf.save(fileName + ".pdf");
|
|
1168
|
+
});
|
|
1169
|
+
}, 2000);
|
|
1170
|
+
onHideElements(false);
|
|
1165
1171
|
};
|
|
1166
1172
|
return /*#__PURE__*/_react["default"].createElement(_Box["default"], null, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
|
|
1167
1173
|
startIcon: startIcon,
|
package/package.json
CHANGED
|
@@ -5,27 +5,35 @@ 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, fileName = "download"}) => {
|
|
8
|
+
export const PageToPDF = ({buttonText = "Download", startIcon = <DownloadRoundedIcon/>, variant = "contained", elementById, scale = 2, onHideElements = null, fileName = "download"}) => {
|
|
9
9
|
|
|
10
10
|
const printElement = () => {
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
onHideElements(true);
|
|
13
|
+
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
|
|
16
|
+
const input = document.getElementById(elementById);
|
|
17
|
+
html2canvas(input, {backgroundColor: null, scale: scale})
|
|
18
|
+
.then((canvas) => {
|
|
19
|
+
const imgData = canvas.toDataURL("image/png", 1.0);
|
|
20
|
+
const pdf = new jsPDF();
|
|
21
|
+
const pdfWidth = pdf.internal.pageSize.getWidth();
|
|
22
|
+
const pdfHeight = pdf.internal.pageSize.getHeight();
|
|
23
|
+
const imgWidth = canvas.width;
|
|
24
|
+
const imgHeight = canvas.height;
|
|
25
|
+
const scaleFactor = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight);
|
|
26
|
+
const scaledWidth = imgWidth * scaleFactor;
|
|
27
|
+
const scaledHeight = imgHeight * scaleFactor;
|
|
28
|
+
const x = (pdfWidth - scaledWidth) / 2;
|
|
29
|
+
const y = 0; // Set y coordinate to 0 to align to the top
|
|
30
|
+
pdf.addImage(imgData, "PNG", x, y, scaledWidth, scaledHeight);
|
|
31
|
+
pdf.save(fileName + ".pdf");
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
}, 2000);
|
|
35
|
+
|
|
36
|
+
onHideElements(false);
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
|