authscape 1.0.133 → 1.0.136
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 +21 -6
- package/package.json +1 -1
- package/src/components/pageToPDF.js +16 -5
package/index.js
CHANGED
|
@@ -726,6 +726,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
726
726
|
var _Box = _interopRequireDefault(require("@mui/material/Box"));
|
|
727
727
|
var _html2canvas = _interopRequireDefault(require("html2canvas"));
|
|
728
728
|
var _jspdf = require("jspdf");
|
|
729
|
+
var _Button = _interopRequireDefault(require("@mui/material/Button"));
|
|
729
730
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
730
731
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
731
732
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -735,18 +736,32 @@ var PageToPDF = function PageToPDF(_ref) {
|
|
|
735
736
|
_ref$variant = _ref.variant,
|
|
736
737
|
variant = _ref$variant === void 0 ? "contained" : _ref$variant,
|
|
737
738
|
elementById = _ref.elementById,
|
|
739
|
+
_ref$scale = _ref.scale,
|
|
740
|
+
scale = _ref$scale === void 0 ? 2 : _ref$scale,
|
|
738
741
|
_ref$fileName = _ref.fileName,
|
|
739
|
-
fileName = _ref$fileName === void 0 ? "download
|
|
742
|
+
fileName = _ref$fileName === void 0 ? "download" : _ref$fileName;
|
|
740
743
|
var printElement = function printElement() {
|
|
741
744
|
var input = document.getElementById(elementById);
|
|
742
|
-
(0, _html2canvas["default"])(input
|
|
743
|
-
|
|
745
|
+
(0, _html2canvas["default"])(input, {
|
|
746
|
+
backgroundColor: null,
|
|
747
|
+
scale: scale
|
|
748
|
+
}).then(function (canvas) {
|
|
749
|
+
var imgData = canvas.toDataURL("image/png", 1.0);
|
|
744
750
|
var pdf = new _jspdf.jsPDF();
|
|
745
|
-
pdf.
|
|
746
|
-
pdf.
|
|
751
|
+
var pdfWidth = pdf.internal.pageSize.getWidth();
|
|
752
|
+
var pdfHeight = pdf.internal.pageSize.getHeight();
|
|
753
|
+
var imgWidth = canvas.width;
|
|
754
|
+
var imgHeight = canvas.height;
|
|
755
|
+
var scaleFactor = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight);
|
|
756
|
+
var scaledWidth = imgWidth * scaleFactor;
|
|
757
|
+
var scaledHeight = imgHeight * scaleFactor;
|
|
758
|
+
var x = (pdfWidth - scaledWidth) / 2;
|
|
759
|
+
var y = 0; // Set y coordinate to 0 to align to the top
|
|
760
|
+
pdf.addImage(imgData, "PNG", x, y, scaledWidth, scaledHeight);
|
|
761
|
+
pdf.save(fileName + ".pdf");
|
|
747
762
|
});
|
|
748
763
|
};
|
|
749
|
-
return /*#__PURE__*/_react["default"].createElement(_Box["default"], null, /*#__PURE__*/_react["default"].createElement(
|
|
764
|
+
return /*#__PURE__*/_react["default"].createElement(_Box["default"], null, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
|
|
750
765
|
variant: variant,
|
|
751
766
|
onClick: function onClick() {
|
|
752
767
|
printElement();
|
package/package.json
CHANGED
|
@@ -2,21 +2,32 @@ import React, {useEffect, useState} from 'react';
|
|
|
2
2
|
import Box from '@mui/material/Box';
|
|
3
3
|
import html2canvas from 'html2canvas';
|
|
4
4
|
import { jsPDF } from "jspdf";
|
|
5
|
+
import Button from "@mui/material/Button";
|
|
5
6
|
|
|
6
|
-
export const PageToPDF = ({buttonText = "Download", variant = "contained", elementById, fileName = "download
|
|
7
|
+
export const PageToPDF = ({buttonText = "Download", variant = "contained", elementById, scale = 2, fileName = "download"}) => {
|
|
7
8
|
|
|
8
9
|
const printElement = () => {
|
|
9
10
|
|
|
10
11
|
const input = document.getElementById(elementById);
|
|
11
|
-
html2canvas(input)
|
|
12
|
+
html2canvas(input, {backgroundColor: null, scale: scale})
|
|
12
13
|
.then((canvas) => {
|
|
13
|
-
const imgData = canvas.toDataURL(
|
|
14
|
+
const imgData = canvas.toDataURL("image/png", 1.0);
|
|
14
15
|
const pdf = new jsPDF();
|
|
15
|
-
pdf.
|
|
16
|
-
pdf.
|
|
16
|
+
const pdfWidth = pdf.internal.pageSize.getWidth();
|
|
17
|
+
const pdfHeight = pdf.internal.pageSize.getHeight();
|
|
18
|
+
const imgWidth = canvas.width;
|
|
19
|
+
const imgHeight = canvas.height;
|
|
20
|
+
const scaleFactor = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight);
|
|
21
|
+
const scaledWidth = imgWidth * scaleFactor;
|
|
22
|
+
const scaledHeight = imgHeight * scaleFactor;
|
|
23
|
+
const x = (pdfWidth - scaledWidth) / 2;
|
|
24
|
+
const y = 0; // Set y coordinate to 0 to align to the top
|
|
25
|
+
pdf.addImage(imgData, "PNG", x, y, scaledWidth, scaledHeight);
|
|
26
|
+
pdf.save(fileName + ".pdf");
|
|
17
27
|
})
|
|
18
28
|
}
|
|
19
29
|
|
|
30
|
+
|
|
20
31
|
return (
|
|
21
32
|
<Box>
|
|
22
33
|
<Button variant={variant} onClick={() => {
|