window.onload = function(){ //GcPdfViewer.LicenseKey = "***key***"; let viewer; let tenantAdded = false, landlordAdded = false; function applyNormalViewerLayout() { viewer.toolbarLayout.viewer = { default: ['doc-title', '$split', 'about'], mobile: ['doc-title', '$split', 'about'], fullscreen: ['$fullscreen', 'doc-title', '$split', 'about'] }; viewer.applyToolbarLayout(); } function applySignedBothViewerLayout() { viewer.toolbarLayout.viewer = { default: ['save', 'doc-title', '$split', 'about'], mobile: ['save', 'doc-title', '$split', 'about'], fullscreen: ['$fullscreen', 'save', 'doc-title', '$split', 'about'] }; viewer.applyToolbarLayout(); } function onSignatureAdded(resultDetails) { viewer.scrollAnnotationIntoView(resultDetails.pageIndex, resultDetails.annotation); if(resultDetails.annotation.subject === 'Tenant') { tenantAdded = true; viewer.removeAnnotation(0, '13R'); viewer.removeAnnotation(0, '15R'); } else if(resultDetails.annotation.subject === 'Landlord') { landlordAdded = true; viewer.removeAnnotation(0, '16R'); viewer.removeAnnotation(0, '14R'); } if(tenantAdded && landlordAdded) { applySignedBothViewerLayout(); } console.log('Added new stamp, subject is ' + resultDetails.annotation.subject); } let options = { workerSrc: "/documents-api-pdfviewer/demos/product-bundles/build/gcpdfviewer.worker.js", supportApi: { apiUrl: window.top.SUPPORTAPI_URL, token: window.top.SUPPORTAPI_TOKEN, webSocketUrl: false }, restoreViewStateOnLoad: false }; options.signTool = { selectedTab: 'Draw', saveSignature: false, penColor: '#000000', penWidth: 2, canvasSize: { width: 320, height: 112 }, autoResizeCanvas: false, dialogLocation: 'Bottom', hideToolbar: true, hideTabs: true, hideFooter: true, hideSaveSignature: true, destinationScale: 0.5, beforeShow: function (dialog) { if(dialog.subject === 'Landlord') { dialog.title = 'Landlord/Lessor'; dialog.location = { x: 87, y: 116 }; } else if(dialog.subject === 'Tenant') { dialog.title = 'Tenant/Lessee'; dialog.location = { x: 345, y: 116 } ; } return true; }, afterAdd: function (result) { onSignatureAdded(result); return true; } }; options.restoreViewStateOnLoad = false; viewer = new GcPdfViewer("#viewer", options); viewer.mouseMode = 1; viewer.addDefaultPanels(); viewer.addAnnotationEditorPanel(); viewer.zoom = 70; applyNormalViewerLayout(); viewer.open("/documents-api-pdfviewer/demos/product-bundles/assets/pdf/viewer-add-signature-using-link.pdf"); }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Add Signature using Link</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="./src/styles.css"> <script src="/documents-api-pdfviewer/demos/product-bundles/build/gcpdfviewer.js"></script> <script src="./src/app.js"></script> </head> <body> <div id="viewer"></div> </body> </html>
#viewer { height: 100%; }