var React, viewer;
window.onload = function(){
viewer = new DsPdfViewer("#viewer", {
workerSrc: "/document-solutions/javascript-pdf-viewer/demos/product-bundles/build/dspdfviewer.worker.js",
supportApi: false
});
viewer.addDefaultPanels();
const toolbarLayout = viewer.toolbarLayout;
toolbarLayout.viewer.mobile = toolbarLayout.viewer.default = ["$navigation", "$zoom"];
React = viewer.getType("React");
// Register custom second toolbar for key "custom-toolbar-key":
viewer.options.secondToolbar = {
render: function(toolbarKey) {
if(toolbarKey === "custom-toolbar-key") {
return [
createOpenPdfButton("realestate-lease.pdf"),
createOpenPdfButton("newsletter.pdf"),
createOpenPdfButton("wetlands.pdf")
];
} else {
return null;
}
}
};
// Show custom second toolbar:
viewer.showSecondToolbar("custom-toolbar-key");
viewer.open("/document-solutions/javascript-pdf-viewer/demos/product-bundles/assets/pdf/realestate-lease.pdf");
}
function createOpenPdfButton(pdfName) {
const pdfUrl = "/document-solutions/javascript-pdf-viewer/demos/product-bundles/assets/pdf/" + pdfName;
const disabled = viewer.fileName === pdfName ? true : false;
return React.createElement("button", { className: "gc-btn gc-btn--accent",
disabled, style: { padding: "0 10px 0 10px" },
onClick: disabled ? null : () => { viewer.open(pdfUrl); },
title: "Open " + pdfName }, pdfName);
}
function createLabel(labelText){
return React.createElement("label", { style: {color: "white"} }, labelText);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Custom second top toolbar</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/app.js"></script>
</head>
<body>
<div id="viewer"></div>
</body>
</html>
#viewer {
height: 100%;
}