プログラムにて個々のページを回転する

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>コードでのページ回転</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/config.js"></script> <script src="./src/app.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(), restoreViewStateOnLoad: false, language: "ja" }; } function configureViewerUI(viewer) { viewer.addDefaultPanels(); viewer.toolbar.addItem({ text: "最初の1ページを回転", title: "最初の1ページを180度回転させる", key: "rotate-first", enabled: false, action: function() { const pageCount = viewer.pageCount; const firstRangeStart = 0, firstRangeEnd = firstRangeStart, secondRangeStart = firstRangeEnd + 1, secondRangeEnd = pageCount - 1; viewer.save(undefined, { pages: `[angle:180]${firstRangeStart}-${firstRangeEnd} ${secondRangeStart}-${secondRangeEnd}`, reload: true, progressTitle: "回転中", progressMessage: "最初の1ページを回転中..." }); }, onUpdate: function() { return { enabled: viewer.hasDocument && viewer.canEditDocument && viewer.pageCount >= 0 }; } }); viewer.toolbar.addItem({ text: "最後の3ページを回転", title: "最後の3ページを180度回転させる", key: "rotate-last-three-pages", enabled: false, action: function() { const pageCount = viewer.pageCount; const firstRangeStart = 0, firstRangeEnd = pageCount - 4, secondRangeStart = pageCount - 3, secondRangeEnd = pageCount - 1; viewer.save(undefined, { pages: `${firstRangeStart}-${firstRangeEnd},[angle:180]${secondRangeStart}-${secondRangeEnd}`, reload: true, progressTitle: "回転中", progressMessage: "最後の3ページを回転中..." }); }, onUpdate: function() { return { enabled: viewer.hasDocument && viewer.canEditDocument && viewer.pageCount > 3 }; } }); viewer.toolbarLayout.viewer.mobile = viewer.toolbarLayout.viewer.default = ["open", "rotate-first", "rotate-last-three-pages", "$navigation", "zoom", "pdf-organizer", "save", "about"]; }