diff --git a/apps/OpenSign/src/components/pdf/PdfHeader.js b/apps/OpenSign/src/components/pdf/PdfHeader.js index f006a8efc..896072f8e 100644 --- a/apps/OpenSign/src/components/pdf/PdfHeader.js +++ b/apps/OpenSign/src/components/pdf/PdfHeader.js @@ -7,6 +7,8 @@ import "../../styles/signature.css"; import * as DropdownMenu from "@radix-ui/react-dropdown-menu"; import { useNavigate } from "react-router-dom"; import { themeColor } from "../../constant/const"; +import Certificate from "./Certificate"; +import { PDFDownloadLink } from "@react-pdf/renderer"; function Header({ isPdfRequestFiles, @@ -91,13 +93,64 @@ function Header({ }; //handle download signed pdf - const handleDownloadCertificate = () => { + const handleDownloadCertificate = async () => { if (pdfDetails?.length > 0 && pdfDetails[0]?.CertificateUrl) { - const certificateUrl = pdfDetails[0] && pdfDetails[0]?.CertificateUrl; - saveAs(certificateUrl, `Certificate_signed_by_OpenSign™.pdf`); + try { + await fetch(pdfDetails[0] && pdfDetails[0]?.CertificateUrl); + const certificateUrl = pdfDetails[0] && pdfDetails[0]?.CertificateUrl; + saveAs(certificateUrl, `Certificate_signed_by_OpenSign™.pdf`); + } catch (err) { + console.log("err in download in certificate", err); + } } }; + const GenerateCertificate = () => { + //after generate download certifcate pdf + const handleDownload = (pdfBlob, fileName) => { + if (pdfBlob) { + const url = window.URL.createObjectURL(pdfBlob); + // Create a temporary anchor element + const link = document.createElement("a"); + link.href = url; + link.download = fileName; + // Append the anchor to the body + document.body.appendChild(link); + // Programmatically click the anchor to trigger the download + link.click(); + // Remove the anchor from the body + document.body.removeChild(link); + // Release the object URL to free up resources + window.URL.revokeObjectURL(url); + } + }; + + return ( + e.preventDefault()} + style={{ textDecoration: "none", zIndex: "35" }} + document={} + > + {({ blob, loading }) => ( + + )} + + ); + }; return (
{isMobile && isShowHeader ? ( @@ -187,21 +240,32 @@ function Header({
{isCompleted && ( - handleDownloadCertificate()} - > -
- - Certificate -
-
+ <> + {pdfDetails[0] && pdfDetails[0]?.CertificateUrl ? ( + handleDownloadCertificate()} + > +
+ + Certificate +
+
+ ) : ( + + + + )} + )} {isSignYourself && ( setIsEditTemplate(true)} - style={{ - border: "none", - outline: "none", - textAlign: "center" - }} + className="outline-none border-none text-center mr-[5px]" > )} + <> + {pdfDetails[0] && pdfDetails[0]?.CertificateUrl ? ( + + ) : ( + + )} + )} + {isCompleted && ( + <> + {pdfDetails[0] && pdfDetails[0]?.CertificateUrl ? ( + + ) : ( + + )} + + )}