MCPcopy Index your code
hub / github.com/OpenSignLabs/OpenSign / handleToPrint

Function handleToPrint

apps/OpenSign/src/constant/Utils.js:3052–3102  ·  view source on GitHub ↗
(event, setIsDownloading, pdfDetails)

Source from the content-addressed store, hash-verified

3050}
3051//function for print digital sign pdf
3052export const handleToPrint = async (event, setIsDownloading, pdfDetails) => {
3053 event.preventDefault();
3054 setIsDownloading("pdf");
3055 const pdfUrl = pdfDetails?.[0]?.SignedUrl || pdfDetails?.[0]?.URL;
3056 const docId = pdfDetails?.[0]?.objectId || "";
3057
3058 try {
3059 // const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
3060 //`localStorage.getItem("baseUrl")` is also use in public-profile flow for public-sign
3061 //if we give this `appInfo.baseUrl` as a base url then in public-profile it will create base url of it's window.location.origin ex- opensign.me which is not base url
3062 const axiosRes = await axios.post(
3063 `${localStorage.getItem("baseUrl")}/functions/getsignedurl`,
3064 {
3065 url: pdfUrl,
3066 docId: docId
3067 },
3068 {
3069 headers: {
3070 "content-type": "Application/json",
3071 "X-Parse-Application-Id": localStorage.getItem("parseAppId"),
3072 "X-Parse-Session-Token": localStorage.getItem("accesstoken")
3073 }
3074 }
3075 );
3076 const url = axiosRes.data.result;
3077 const pdf = await getBase64FromUrl(url);
3078 const isAndroidDevice = navigator.userAgent.match(/Android/i);
3079 const isAppleDevice =
3080 (/iPad|iPhone|iPod/.test(navigator.platform) ||
3081 (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1)) &&
3082 !window.MSStream;
3083 if (isAndroidDevice || isAppleDevice) {
3084 const byteArray = Uint8Array.from(
3085 atob(pdf)
3086 .split("")
3087 .map((char) => char.charCodeAt(0))
3088 );
3089 const blob = new Blob([byteArray], { type: "application/pdf" });
3090 const blobUrl = URL.createObjectURL(blob);
3091 window.open(blobUrl, "_blank");
3092 setIsDownloading("");
3093 } else {
3094 printModule({ printable: pdf, type: "pdf", base64: true });
3095 setIsDownloading("");
3096 }
3097 } catch (err) {
3098 setIsDownloading("");
3099 console.log("err in getsignedurl", err);
3100 alert(i18n.t("something-went-wrong-mssg"));
3101 }
3102};
3103const downloadCertificate = async (certificate, isZip, asBlob) => {
3104 try {
3105 const appName = "OpenSign™";

Callers 4

HeaderFunction · 0.90
EmailComponentFunction · 0.90
PdfRequestFilesFunction · 0.90
DocSuccessPageFunction · 0.90

Calls 1

getBase64FromUrlFunction · 0.85

Tested by

no test coverage detected