window.onload = function(){
var viewer = new DsPdfViewer("#viewer", getViewerOptions());
configureViewerUI(viewer);
viewer.open("/diodocs/pdfviewer/demos/product-bundles/assets/pdf/AcmeFinancialReport.pdf");
}
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>プログラムにてPDFを個別の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>
<script src="./src/config.js"></script>
</head>
<body>
<div id="viewer"></div>
</body>
</html>
#viewer {
height: 100%;
}
function getViewerOptions() {
return {
workerSrc: "/diodocs/pdfviewer/demos/product-bundles/build/dspdfviewer.worker.js",
supportApi: getSupportApiSettings(),
friendlyFileName: "split-pdf.pdf",
restoreViewStateOnLoad: false,
language: "ja"
};
}
function configureViewerUI(viewer) {
viewer.toggleSidebar(false);
viewer.toolbar.addItem({
text: "偶数ページ",
title: "現在のドキュメントの偶数ページのみからPDFを作成する",
key: "even-pages",
enabled: false,
action: async function () {
let pages = "";
for (let i = 0; i < viewer.pageCount; i += 2) {
pages += "," + i;
}
// alert(pages);
await viewer.save("even-pages.pdf", { pages: pages });
},
onUpdate: function () { return { enabled: viewer.hasDocument && viewer.canEditDocument }; }
});
viewer.toolbar.addItem({
text: "最終ページ",
title: "現在のドキュメントの最終ページのみからPDFを作成する",
key: "last-page",
enabled: false,
action: function () {
const lastPageIndex = viewer.pageCount - 1;
viewer.save("last-page.pdf", { pages: lastPageIndex + "-" + lastPageIndex });
},
onUpdate: function () { return { enabled: viewer.hasDocument && viewer.canEditDocument }; }
});
viewer.toolbarLayout.viewer.mobile = viewer.toolbarLayout.viewer.default = ["open", '$navigation', "even-pages", "last-page", "pdf-organizer", "about"];
}