authscape 1.0.134 → 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 CHANGED
@@ -736,15 +736,29 @@ var PageToPDF = function PageToPDF(_ref) {
736
736
  _ref$variant = _ref.variant,
737
737
  variant = _ref$variant === void 0 ? "contained" : _ref$variant,
738
738
  elementById = _ref.elementById,
739
+ _ref$scale = _ref.scale,
740
+ scale = _ref$scale === void 0 ? 2 : _ref$scale,
739
741
  _ref$fileName = _ref.fileName,
740
- fileName = _ref$fileName === void 0 ? "download.pdf" : _ref$fileName;
742
+ fileName = _ref$fileName === void 0 ? "download" : _ref$fileName;
741
743
  var printElement = function printElement() {
742
744
  var input = document.getElementById(elementById);
743
- (0, _html2canvas["default"])(input).then(function (canvas) {
744
- var imgData = canvas.toDataURL('image/png');
745
+ (0, _html2canvas["default"])(input, {
746
+ backgroundColor: null,
747
+ scale: scale
748
+ }).then(function (canvas) {
749
+ var imgData = canvas.toDataURL("image/png", 1.0);
745
750
  var pdf = new _jspdf.jsPDF();
746
- pdf.addImage(imgData, 'JPEG', 0, 0);
747
- pdf.save(fileName);
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");
748
762
  });
749
763
  };
750
764
  return /*#__PURE__*/_react["default"].createElement(_Box["default"], null, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.134",
3
+ "version": "1.0.136",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -4,20 +4,30 @@ import html2canvas from 'html2canvas';
4
4
  import { jsPDF } from "jspdf";
5
5
  import Button from "@mui/material/Button";
6
6
 
7
- export const PageToPDF = ({buttonText = "Download", variant = "contained", elementById, fileName = "download.pdf"}) => {
7
+ export const PageToPDF = ({buttonText = "Download", variant = "contained", elementById, scale = 2, fileName = "download"}) => {
8
8
 
9
9
  const printElement = () => {
10
10
 
11
11
  const input = document.getElementById(elementById);
12
- html2canvas(input)
12
+ html2canvas(input, {backgroundColor: null, scale: scale})
13
13
  .then((canvas) => {
14
- const imgData = canvas.toDataURL('image/png');
14
+ const imgData = canvas.toDataURL("image/png", 1.0);
15
15
  const pdf = new jsPDF();
16
- pdf.addImage(imgData, 'JPEG', 0, 0);
17
- pdf.save(fileName);
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");
18
27
  })
19
28
  }
20
29
 
30
+
21
31
  return (
22
32
  <Box>
23
33
  <Button variant={variant} onClick={() => {