リンクを使用して電子署名を追加する

このサンプルでは、リンク注釈を使用して電子署名を追加する方法を紹介しています。

window.onload = function(){ //DsPdfViewer.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('新しいスタンプを追加しました。件名は ' + resultDetails.annotation.subject); } let options = { workerSrc: "/diodocs/pdfviewer/demos/product-bundles/build/dspdfviewer.worker.js", supportApi: getSupportApiSettings(), 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 = '賃貸人の署名'; dialog.location = { x: 87, y: 116 }; } else if(dialog.subject === 'Tenant') { dialog.title = '賃借人の署名'; dialog.location = { x: 345, y: 116 } ; } return true; }, afterAdd: function (result) { onSignatureAdded(result); return true; } }; options.restoreViewStateOnLoad = false; viewer = new DsPdfViewer("#viewer", options); viewer.mouseMode = 1; viewer.addDefaultPanels(); viewer.addAnnotationEditorPanel(); viewer.zoom = 70; applyNormalViewerLayout(); viewer.open("/diodocs/pdfviewer/demos/product-bundles/assets/pdf/viewer-add-signature-using-link.pdf"); }
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>リンクを使用した電子署名の追加</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="./src/styles.css"> <script src="/diodocs/pdfviewer/demos/product-bundles/build/dspdfviewer.js"></script> <script src="/diodocs/pdfviewer/demos/product-bundles/build/wasmSupportApi.js"></script> <script src="/diodocs/pdfviewer/demos/resource/js/init.js"></script> <script src="./src/app.js"></script> </head> <body> <div id="viewer"></div> </body> </html>
#viewer { height: 100%; }