window.onload = function() { //GcPdfViewer.LicenseKey = "***key***"; let viewer; function updateDestinationLocation(destinationSize) { if(viewer) { var options = viewer.options; var pageSize = viewer.getPageSize(0); options.signTool.location = {x: 80, y: 100}; } } function onSignatureAdded(resultDetails) { viewer.scrollAnnotationIntoView(resultDetails.pageIndex, resultDetails.annotation); } 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 = { ruler: { Draw: [{ color: '#ffe21e', size: 2, type: 'solid', position: 20 }, { color: '#ff0000', size: 5, type: 'dashed', position: 50 }, { color: '#ffe21e', size: 2, type: 'solid', position: 80 } ], Type: [{ color: '#717171', size: 1, type: 'dashed', position: 30 } ] }, afterShow: function(dialog) { updateDestinationLocation(dialog.destinationSize); }, afterAdd: function (result) { onSignatureAdded(result); return true; } }; options.restoreViewStateOnLoad = false; viewer = new GcPdfViewer("#viewer", options); viewer.addDefaultPanels(); viewer.addAnnotationEditorPanel(); viewer.toolbarLayout.viewer = { default: ['open', 'save', 'edit-sign-tool', 'edit-undo', 'doc-title', '$split', 'about'], mobile: ['open', 'save', 'edit-sign-tool', 'edit-undo', 'doc-title', '$split', 'about'], fullscreen: ['$fullscreen', 'open', 'save', 'edit-sign-tool', 'edit-undo', 'doc-title', '$split', 'about'] }; viewer.toolbarLayout.annotationEditor = { default: ['open', 'save', 'edit-sign-tool', 'edit-undo', 'doc-title', '$split', 'about'], mobile: ['open', 'save', 'edit-sign-tool', 'edit-undo', 'doc-title', '$split', 'about'], fullscreen: ['$fullscreen', 'open', 'save', 'edit-sign-tool', 'edit-undo', 'doc-title', '$split', 'about'] }; viewer.applyToolbarLayout(); viewer.zoom = 70; viewer.onAfterOpen.register(function() { viewer.showSignTool(); }); viewer.open("/documents-api-pdfviewer/demos/product-bundles/assets/pdf/viewer-signature-ruler.pdf"); }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Graphical Signature Ruler</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%; }