Code Monkey home page Code Monkey logo

bookstack-pdf-viewer's Introduction

bookstack-pdf-viewer

Step by step to setup pdf-viewer for bookstack app

Step #1

Download PDFJS prebuilt version from https://mozilla.github.io/pdf.js/getting_started/#download Unzip the file to 'pdfjs' folder and move it to the BookStack app 'public' folder. Ensure both 'build' and 'web' folders and its files are there.

Step #2 configure bookstack

All the below steps assume that you are using docker for the bookstack deployment

2.1 copy the pdfjs folder to public folder

docker cp pdfjs bookstack:/app/www/public
docker exec -it bookstack bash
#This is a workaround step to fix an issue with web/viewer.html, it intends to include pdf.worker.js not pdf.worker.mjs
cd /app/www/public/pdfjs/build/
cp pdf.worker.mjs pdf.worker.js

image

2.2 Config nginx to treat the mjs file as javascript

All of the below steps should be executed in bookstack docker container

vi /etc/nginx/mime.types

Replace this line

From

application/javascript                           js;

To

application/javascript                           js mjs;

Then reload the nginx config

/usr/sbin/nginx -s reload

2.3 Copy and paste the following code to Custom HTML Head Content field on Settings page -> Customization

<script type="text/javascript">

  // ------------------- THIS SECTION ADDS A PDF BUTTON TO THE EDITOR TOOLBAR THAT ALLOWS YOU TO EMBED PDFS 

  // Use BookStack editor event to add custom "Insert PDF" button into main toolbar
  window.addEventListener('editor-tinymce::pre-init', event => {
      const mceConfig = event.detail.config;
      mceConfig.toolbar = mceConfig.toolbar.replace('link', 'link insertpdf')
  });

  // Use BookStack editor event to define the custom "Insert PDF" button.
  window.addEventListener('editor-tinymce::setup', event => {
    const editor = event.detail.editor;

    // Add PDF insert button
    editor.ui.registry.addButton('insertpdf', {
      tooltip: 'Insert PDF',
      icon: 'document-properties',
      onAction() {
        editor.windowManager.open({
          title: 'Insert PDF',
          body: {
            type: 'panel',
            items: [
              {type: 'textarea', name: 'pdfurl', label: 'PDF URL'}
            ]
          },
          onSubmit: function(e) {
            // Insert content when the window form is submitted
            editor.insertContent(`<iframe id="pdf-viewer" title="PDF viwer" src="/pdfjs/web/viewer.html?file=${e.getData().pdfurl}" width="100%" height="450vh"></iframe>`);
            e.close();
          },
          buttons: [
            {
              type: 'submit',
              text: 'Insert PDF'
            }
          ]
        });
      }
    });

  });
</script>

Insert PDF Button

image

Insert PDF Form input

image

Insert PDF Editor

image

PDF Viewer

image

Appendix

Persit changes

If you want to preserve the changes, which is helpful for those who want to regularly upgrade the BookStack image, please follow the instructions mentioned here

How to deal with problem on docker image update

Shadow effect

A small tweak if you want to strengthen the shadow to make the page appear closer to the reader and focus more on the content

<style>
.page-content clearfix {
 font-size: 14px;
}
#bkmrk-page-title {
    font-size: 35px;
}
.card {
    background-color: #fff;
    box-shadow: 0 20px 60px -1px rgba(0,0,0,.1);
    border-radius: 10px;
    border: 1px solid transparent;
}


.tri-layout-middle-contents {
    max-width: unset;
}
</style>

image

bookstack-pdf-viewer's People

Contributors

depripramana avatar ddkhanh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.