function getViewerOptions() {
return {
workerSrc: "/diodocs/pdfviewer/demos/product-bundles/build/dspdfviewer.worker.js",
supportApi: {
apiUrl: window.top.SUPPORTAPI_URL, token: window.top.SUPPORTAPI_TOKEN, webSocketUrl: false
},
restoreViewStateOnLoad: false,
language: "ja"
};
}
function configureViewerUI(viewer) {
var documentSigned = false;
viewer.addDefaultPanels();
viewer.addAnnotationEditorPanel();
viewer.addFormEditorPanel();
viewer.onAfterOpen.register(function() {
viewer.getSignatureInfo().then(function (info) {
documentSigned = info.signed;
});
});
// ドキュメントがデジタル署名を使用して署名されている場合、編集イベントをキャンセル
const onBeforeEditHandler = (args) => {
const cancel = documentSigned && args.annotation.annotationType !== 13 /* スタンプ注釈の編集は許可 */;
if(cancel) {
args.cancel = true;
setTimeout(()=> {
viewer.showMessage("署名されたドキュメントは編集できません。", "このドキュメントは、デジタル署名にて署名されています。", "warn");
viewer.hideSecondToolbar();
viewer.layoutMode = 0;
viewer.editMode = 0;
viewer.repaint();
}, 200);
}
};
viewer.onBeforeAddAnnotation.register(onBeforeEditHandler);
viewer.onBeforeUpdateAnnotation.register(onBeforeEditHandler);
viewer.onBeforeRemoveAnnotation.register(onBeforeEditHandler);
}
window.onload = function() {
var viewer = new DsPdfViewer("#viewer", getViewerOptions());
configureViewerUI(viewer);
viewer.open("/diodocs/pdfviewer/demos/product-bundles/assets/pdf/prevent-editing-signed-pdf.pdf");
}
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>署名 PDF の編集を禁止</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%;
}