1.0.11 • Published 1 year ago

@eeacms/volto-pdf-block v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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)

1.0.11

1 year ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago