import React from "react"; import RSC from "react-scrollbars-custom"; import { Document, Page, pdfjs } from "react-pdf"; import { addZIndex, defaultWidthHeight, handleImageResize, handleSignYourselfImageResize } from "../../utils/Utils"; import EmailToast from "./emailToast"; // import PlaceholderBorder from "./placeholderBorder"; import Placeholder from "../WidgetComponent/placeholder"; pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`; function RenderPdf({ pageNumber, pdfOriginalWidth, pdfNewWidth, drop, signerPos, successEmail, handleTabDrag, handleStop, isDragging, setIsSignPad, setIsStamp, handleDeleteSign, setSignKey, pdfDetails, xyPostion, pdfUrl, numPages, pageDetails, pdfRequest, setCurrentSigner, signerObjectId, signedSigners, setPdfLoadFail, placeholder, pdfLoadFail, setSignerPos, setXyPostion, index, containerWH, setIsResize, handleLinkUser, setUniqueId, signersdata, setIsPageCopy, setSignerObjId, setShowDropdown, setIsInitial, setIsCheckboxRequired, setIsValidate, setWidgetType, setValidateAlert, setIsRadio, setCurrWidgetsDetails, setSelectWidgetId, selectWidgetId, unSignedWidgetId }) { const isMobile = window.innerWidth < 767; const newWidth = containerWH.width; const scale = isMobile ? pdfOriginalWidth / newWidth : 1; //check isGuestSigner is present in local if yes than handle login flow header in mobile view const isGuestSigner = localStorage.getItem("isGuestSigner"); // handle signature block width and height according to screen const posWidth = (pos, signYourself) => { const defaultWidth = defaultWidthHeight(pos.type).width; const posWidth = pos.Width ? pos.Width : defaultWidth; let width; if (signYourself) { width = posWidth; return width; } else { if (isMobile) { if (!pos.isMobile) { if (pos.IsResize) { width = posWidth ? posWidth : defaultWidth; return width; } else { width = (posWidth || defaultWidth) / scale; return width; } } else { width = posWidth; return width; } } else { if (pos.isMobile) { if (pos.IsResize) { width = posWidth ? posWidth : defaultWidth; return width; } else { width = (posWidth || defaultWidth) * pos.scale; return width; } } else { width = posWidth ? posWidth : defaultWidth; return width; } } } }; const posHeight = (pos, signYourself) => { let height; const posHeight = pos.Height; const defaultHeight = defaultWidthHeight(pos.type).height; if (signYourself) { height = posHeight ? posHeight : defaultHeight; return height; } else { if (isMobile) { if (!pos.isMobile) { if (pos.IsResize) { height = posHeight ? posHeight : defaultHeight; return height; } else { height = (posHeight || defaultHeight) / scale; return height; } } else { height = posHeight ? posHeight : defaultHeight; return height; } } else { if (pos.isMobile) { if (pos.IsResize) { height = posHeight ? posHeight : defaultHeight; return height; } else { height = (posHeight || defaultHeight) * pos.scale; return height; } } else { height = posHeight ? posHeight : defaultHeight; return height; } } } }; const xPos = (pos, signYourself) => { const resizePos = pos.xPosition; if (signYourself) { return resizePos; } else { //checking both condition mobile and desktop view if (isMobile) { //if pos.isMobile false -- placeholder saved from desktop view then handle position in mobile view divided by scale if (!pos.isMobile) { return resizePos / scale; } //pos.isMobile true -- placeholder save from mobile view(small device) handle position in mobile view(small screen) view divided by scale else { return resizePos * (pos.scale / scale); } } else { //else if pos.isMobile true -- placeholder saved from mobile or tablet view then handle position in desktop view divide by scale if (pos.isMobile) { return pos.scale && resizePos * pos.scale; } //else placeholder save from desktop(bigscreen) and show in desktop(bigscreen) else { return resizePos; } } } }; const yPos = (pos, signYourself) => { const resizePos = pos.yPosition; if (signYourself) { return resizePos; } else { //checking both condition mobile and desktop view if (isMobile) { //if pos.isMobile false -- placeholder saved from desktop view then handle position in mobile view divided by scale if (!pos.isMobile) { return resizePos / scale; } //pos.isMobile true -- placeholder save from mobile view(small device) handle position in mobile view(small screen) view divided by scale else { return resizePos * (pos.scale / scale); } } else { //else if pos.isMobile true -- placeholder saved from mobile or tablet view then handle position in desktop view divide by scale if (pos.isMobile) { return pos.scale && resizePos * pos.scale; } //else placeholder save from desktop(bigscreen) and show in desktop(bigscreen) else { return resizePos; } } } }; //function for render placeholder block over pdf document const checkSignedSignes = (data) => { const checkSign = signedSigners.filter( (sign) => sign.objectId === data.signerObjId ); if (data.signerObjId === signerObjectId) { setCurrentSigner(true); } const handleAllUserName = () => { pdfDetails[0].Signers.map((signerData, key) => { return ( signerData.objectId === data.signerObjId && (
{signerData.Name}
) ); }); }; return ( checkSign.length === 0 && data.placeHolder.map((placeData, key) => { return ( {placeData.pageNumber === pageNumber && placeData.pos.map((pos, index) => { return ( pos && ( ) ); })} ); }) ); }; const handleUserName = (Id, Role) => { if (Id) { const checkSign = signersdata.find((sign) => sign.Id === Id); if (checkSign?.Name) { return ( <>
{checkSign?.Name}
{`(${Role})`}
); } else { return
{Role}
; } } else { return
{Role}
; } }; return ( <> {isMobile && scale ? (
{pdfLoadFail.status && (pdfRequest ? signerPos.map((data, key) => { return ( {checkSignedSignes(data)} ); }) : placeholder // placeholder mobile ? signerPos.map((data, ind) => { return ( {data.placeHolder.map((placeData, index) => { return ( {placeData.pageNumber === pageNumber && placeData.pos.map((pos) => { return ( ); })} ); })} ); }) : xyPostion.map((data, ind) => { return ( {data.pageNumber === pageNumber && data.pos.map((pos) => { return ( pos && ( ) ); })} ); }))} {/* this component for render pdf document is in middle of the component */}
{ setPdfLoadFail(true); }} loading={"Loading Document.."} onLoadSuccess={pageDetails} // ref={pdfRef}' onClick={() => { if (setSelectWidgetId) { setSelectWidgetId(""); } }} file={ pdfUrl ? pdfUrl : pdfDetails[0] && pdfDetails[0].SignedUrl ? pdfDetails[0].SignedUrl : pdfDetails[0].URL } > {Array.from(new Array(numPages), (el, index) => ( { console.log("annotation error", error); }} /> ))}
) : ( pdfNewWidth ? pdfNewWidth : pdfOriginalWidth, height: window.innerHeight - 110 + "px" }} noScrollY={false} noScrollX={pdfNewWidth < pdfOriginalWidth ? false : true} >
{pdfLoadFail.status && (pdfRequest ? signerPos.map((data, key) => { return ( {checkSignedSignes(data)} ); }) : placeholder ? signerPos.map((data, ind) => { return ( {data.placeHolder.map((placeData, index) => { return ( {placeData.pageNumber === pageNumber && placeData.pos.map((pos) => { return ( ); })} ); })} ); }) : xyPostion.map((data, ind) => { return ( {data.pageNumber === pageNumber && data.pos.map((pos) => { return ( pos && ( handleStop(event, dragElement, pos.type) } handleSignYourselfImageResize={ handleSignYourselfImageResize } index={index} xyPostion={xyPostion} setXyPostion={setXyPostion} pdfOriginalWidth={pdfOriginalWidth} containerWH={containerWH} setIsSignPad={setIsSignPad} isShowBorder={true} isSignYourself={true} xPos={xPos} yPos={yPos} posWidth={posWidth} posHeight={posHeight} pdfDetails={pdfDetails[0]} isDragging={isDragging} setIsInitial={setIsInitial} setWidgetType={setWidgetType} setSelectWidgetId={setSelectWidgetId} selectWidgetId={selectWidgetId} /> ) ); })} ); }))} {/* this component for render pdf document is in middle of the component */} { const load = { status: false, type: "failed" }; setPdfLoadFail(load); }} loading={"Loading Document.."} onLoadSuccess={pageDetails} onClick={() => { if (setSelectWidgetId) { setSelectWidgetId(""); } }} // ref={pdfRef} file={ pdfUrl ? pdfUrl : pdfDetails[0] && pdfDetails[0].SignedUrl ? pdfDetails[0].SignedUrl : pdfDetails[0].URL } > {Array.from(new Array(numPages), (el, index) => ( { console.log("annotation error", error); }} /> ))}
)} ); } export default RenderPdf;