1.2.0 • Published 27 days ago

@cincel.digital/react v1.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
27 days ago

@cincel.digital/react

Installation

yarn add @cincel.digital/react

# or

npm i @cincel.digital/react

Usage

Basic

import * as React from "react"
import {
  PDFViewer,
  PdfViewer,
  PdfViewerCloseButton,
  PdfViewerContent,
  PdfViewerRenderer,
  PdfViewerToolbar,
} from "@cincel.digital/react"

const pv = new PDFViewer({ mode: "read" })
pv.debug = true

function IntegrationTest() {
  const [file, setFile] = React.useState<File | null>(null)

  const handleFileUpload = async (
    event: React.ChangeEvent<HTMLInputElement>,
  ) => {
    const file = event.target.files?.[0]
    if (!file) return

    setFile(file)
  }

  return (
    <PdfViewer
      pdfViewer={pv}
      file={file}
      url="https://dev.api.cincel.digital/v3/convert-to-pdf"
      onClose={() => setFile(null)}
      renderEmptyState={(state) => {
        if (state.loading) {
          return <pre>Converting to PDF...</pre>
        } else if (state.empty) {
          return (
            <div>
              <pre>Select a document to convert to PDF.</pre>
              <input
                type="file"
                title="Select a file"
                onChange={handleFileUpload}
              />
              {state.error && <pre>{JSON.stringify(state.error.message)}</pre>}
            </div>
          )
        }
      }}
    >
      <PdfViewerContent>
        <PdfViewerCloseButton />
        <PdfViewerToolbar />
        <PdfViewerRenderer />
      </PdfViewerContent>
    </PdfViewer>
  )
}

Customize the layout

The React integration is built upon an anatomy, which allows for composing the layout in any desired way. Custom styles can be passed to the Reactish, or grouped into multiple elements to achieve the desired effect/layout. For instance, to customize the toolbar, a render prop is provided, enabling the replacement of the render without complications.

<div className="flex space-x-4">
  <PdfViewerToolbar>
    {({ toolbar }) => (
      <div>
        <button onClick={toolbar.fullscreen}>fullscreen</button>
        <button onClick={toolbar.zoomIn}>Zoom in</button>
        <button onClick={toolbar.zoomOut}>Zoom out</button>
      </div>
    )}
  </PdfViewerToolbar>
  <PdfViewerToolbar>
    {({ toolbar }) => (
      <div>
        <button onClick={toolbar.text}>Free text</button>
        <button onClick={toolbar.signature}>Add signature</button>
      </div>
    )}
  </PdfViewerToolbar>
</div>

This is the value for the Toolbar:

PropertyDescription
textCallback function for the "text" action. Invoked when the "Free text" button is clicked.
dateCallback function for the "date" action. Invoked when the "Add date" button is clicked.
signatureCallback function for the "signature" action. Invoked when the "Add signature" button is clicked.
zoomInFunction to zoom in the PDF Viewer.
zoomOutFunction to zoom out the PDF Viewer.
fullscreenFunction to toggle fullscreen mode for the PDF Viewer.

Please note that the annotations(text, date & signature) will only be present if the Viewer was created in edit mode.

const pv = new PDFViewer({ mode: "edit" })

TODO

Get annotations Set annotations

1.2.1-dev.8

27 days ago

1.2.1-dev.7

7 months ago

1.2.1-dev.6

7 months ago

1.2.1-dev.5

8 months ago

1.2.1-dev.4

8 months ago

1.2.1-dev.3

8 months ago

1.2.1-dev.2

9 months ago

1.2.1-dev.1

9 months ago

1.2.1-dev.0

9 months ago

1.2.0

9 months ago

1.2.0-dev.26

9 months ago

1.2.0-dev.25

9 months ago

1.2.0-dev.24

10 months ago

1.2.0-dev.23

10 months ago

1.2.0-dev.22

10 months ago

1.2.0-dev.21

10 months ago

1.2.0-dev.20

10 months ago

1.2.0-dev.19

10 months ago

1.2.0-dev.18

10 months ago

1.2.0-dev.17

10 months ago

1.2.0-dev.16

10 months ago

1.2.0-dev.15

10 months ago

1.2.0-dev.14

10 months ago

1.2.0-dev.13

10 months ago

1.2.0-dev.12

10 months ago

1.2.0-dev.11

10 months ago

1.2.0-dev.10

10 months ago

1.2.0-dev.9

10 months ago

1.2.0-dev.8

10 months ago

1.2.0-dev.7

10 months ago

1.2.0-dev.6

10 months ago

1.2.0-dev.5

10 months ago

1.2.0-dev.4

10 months ago

1.2.0-dev.3

10 months ago

1.2.0-dev.2

10 months ago

1.2.0-dev.1

10 months ago

1.2.0-dev.0

10 months ago