@eeacms/volto-pdf-block

1.0.11 • Public • Published

volto-pdf-block

Releases

Pipeline Lines of Code Coverage Bugs Duplicated Lines (%)

Pipeline Lines of Code Coverage Bugs Duplicated Lines (%)

Volto add-on

Features

  • Flexible PDF integration in Volto.

NOTE: this addon assumes that, if you're trying to load external hosted PDF files, you will be using @eeacms/volto-corsproxy

Getting started

Add volto-pdf-block to your Volto project

  1. Make sure you have a Plone backend up-and-running at http://localhost:8080/Plone

  2. Start Volto frontend

  • If you already have a volto project, just update package.json:

    "addons": [
        "@eeacms/volto-pdf-block"
    ],
    
    "dependencies": {
        "@eeacms/volto-pdf-block": "*"
    }
  • If not, create one:

    npm install -g yo @plone/generator-volto
    yo @plone/volto my-volto-project --canary --addon @eeacms/volto-pdf-block
    cd my-volto-project
    
  1. Install new add-ons and restart Volto:

    yarn
    yarn start
    
  2. Go to http://localhost:3000

  3. Happy editing!

Internal use of PDF library

import config from '@plone/volto/registry';
import PDF from '@mikecousins/react-pdf';


export const PdfViwer = (props) => {

return (
  <PDF
    file={source.file || source.url}
    content={source.base64}
    binaryContent={source.binary}
    documentInitParameters={source.connection}
    page={page}
    scale={scale}
    onPageRenderSuccess={onPageRenderSuccess}
    onPageRenderFail={onPageRenderFail}
    workerSrc={config.settings.pdfWorkerSrc}
    onDocumentLoadSuccess={onDocumentComplete}
  >
    {({ pdfDocument, pdfPage, canvas }) => (
    <>
      {!pdfDocument && loaderComponent(canvas)}
      {pdfDocument && canvas}
    </>
    )}
  </PDF>
)}

workerSrc

Allows you to specify your own url for the pdf worker. Default is set by the library to:

"//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js"

For cases where it is needed to have the library on a different CDN this can be configured on config.settings.pdfWorkerSrc the way it is done on volto-ims-policy which is an add-on that centrilazes configurations for Volto for different add-ons.

const applyConfig = (config) => {
  ...
  // PDF worker url
  config.settings.pdfWorkerSrc = '//www.eea.europa.eu/pdfjs/pdf.worker.min.js';
  return config;
};

Release

See RELEASE.md.

How to contribute

See DEVELOP.md.

Copyright and license

The Initial Owner of the Original Code is European Environment Agency (EEA). All Rights Reserved.

See LICENSE.md for details.

Funding

European Environment Agency (EU)

Package Sidebar

Install

npm i @eeacms/volto-pdf-block

Weekly Downloads

57

Version

1.0.11

License

MIT

Unpacked Size

69.8 kB

Total Files

26

Last publish

Collaborators

  • nileshgulia1
  • valentinab25
  • demarant
  • avoinea
  • tiberiuichim
  • zotya
  • alecghica
  • eea-jenkins
  • razvan.miu
  • ichimdav