1.1.1 • Published 11 months ago

@component-hook/pdf-canvas v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@component-hook/pdf-canvas

Rendering PDF documents onto a canvas with vue3 and react component.
Implementation depository: PDF-signature

Features

  • Rendering PDF documents onto a canvas
  • Open encrypted PDF files
  • Drag and drop the images and text onto the canvas
  • Manually add the images and text onto the canvas
  • Full TypeScript support

Documentation

For detailed documentation and usage examples, please visit: Official Docs.

Installation

# Using npm
$ npm install @component-hook/pdf-canvas

# Using yarn
$ yarn add @component-hook/pdf-canvas

# Using pnpm
$ pnpm install @component-hook/pdf-canvas

Base Usage

Vue3

<script setup lang="ts">
import PdfCanvas, { loadFile, type PDF } from '@component-hook/pdf-canvas/vue';
import { ref } from 'vue';

const currentPdf = ref<PDF>();

async function uploadFile(event: Event) {
  const target = event.target as HTMLInputElement;
  const { files } = target;

  if (!files) return;
  const file = files[0];
  const content = await loadFile(file);

  currentPdf.value = content;
  target.value = '';
}
</script>

<template>
  <div class="w-fit flex flex-col items-center gap-3">
    <pdf-canvas
      v-if="currentPdf"
      :file="currentPdf"
    />

    <p
      v-else
      class="font-mono text-sm"
    >
      Please select a PDF file or image.
    </p>

    <button class="relative">
      <input
        type="file"
        accept="application/pdf, .jpg, .png"
        class="opacity-0 top-0 left-0 absolute w-[94px] h-[36px] cursor-pointer"
        @change="uploadFile"
      />
      select file
    </button>
  </div>
</template>

React

import PdfCanvas, { loadFile, type PDF } from '@component-hook/pdf-canvas/react';
import { useState, type ChangeEvent } from 'react';

export function DrawPdf() {
  const [currentPdf, setCurrentPdf] = useState<PDF>();

  const uploadFile = async (event: ChangeEvent<HTMLInputElement>) => {
    const target = event.target;
    const { files } = target;

    if (!files || files.length === 0) return;

    const file = files[0];
    const content = await loadFile(file);

    setCurrentPdf(content);
    target.value = '';
  };

  return (
    <div>
      {currentPdf ? <PdfCanvas file={currentPdf} /> : <p>Please select a PDF file or image.</p>}

      <button>
        <input
          type="file"
          accept="application/pdf, .jpg, .png"
          onChange={uploadFile}
        />
        select file
      </button>
    </div>
  );
}

License

This project is licensed under the MIT License.

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.1.0-alpha.11

11 months ago

1.1.0-alpha.10

12 months ago

1.1.0-alpha.12

11 months ago

1.0.4

12 months ago

1.0.3

1 year ago

0.2.1-alpha.0

1 year ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.5-alpha.0

12 months ago

1.0.5-alpha.2

12 months ago

1.0.5-alpha.1

12 months ago

0.2.0-alpha.0

1 year ago

0.2.0-alpha.1

1 year ago

1.0.5-alpha.4

12 months ago

1.0.5-alpha.3

12 months ago

1.1.0-alpha.9

12 months ago

1.1.0-alpha.7

12 months ago

1.1.0-alpha.8

12 months ago

1.1.0-alpha.1

12 months ago

1.1.0-alpha.2

12 months ago

0.2.1

1 year ago

1.1.0-alpha.0

12 months ago

0.2.0

1 year ago

1.1.0-alpha.5

12 months ago

1.1.0-alpha.6

12 months ago

1.1.0-alpha.3

12 months ago

1.1.0-alpha.4

12 months ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.3-alpha.8

2 years ago

0.1.3-alpha.7

2 years ago

0.1.3-alpha.6

2 years ago

0.1.3-alpha.5

2 years ago

0.1.3-alpha.4

2 years ago

0.1.3-alpha.3

2 years ago

0.1.3-alpha.2

2 years ago

0.1.3-alpha.1

2 years ago

0.1.3-alpha.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago