window.onload = function(){
var viewer = new DsPdfViewer("#viewer", getViewerOptions());
configureViewerUI(viewer);
viewer.open("/document-solutions/javascript-pdf-viewer/demos/product-bundles/assets/pdf/rotate-pages.pdf");
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Rotate individual pages programmatically</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./src/styles.css">
<script src="/document-solutions/javascript-pdf-viewer/demos/product-bundles/build/dspdfviewer.js"></script>
<script src="/document-solutions/javascript-pdf-viewer/demos/product-bundles/build/wasmSupportApi.js"></script>
<script src="/document-solutions/javascript-pdf-viewer/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: "/document-solutions/javascript-pdf-viewer/demos/product-bundles/build/dspdfviewer.worker.js",
supportApi: getSupportApiSettings(),
restoreViewStateOnLoad: false
};
}
function configureViewerUI(viewer) {
viewer.addDefaultPanels();
viewer.toolbar.addItem({
text: "Rotate first page",
title: "Rotate the first page 180 degrees",
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: "Rotating", progressMessage: "Rotating first page..." });
},
onUpdate: function() { return { enabled: viewer.hasDocument && viewer.canEditDocument && viewer.pageCount >= 0 }; }
});
viewer.toolbar.addItem({
text: "Rotate last three pages",
title: "Rotate the last three pages 180 degrees",
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: "Rotating", progressMessage: "Rotating last three pages..." });
},
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"];
}