CofCat456 / vue-pdf-printer

A lightweight tool for printing Vue components to PDF.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vue-pdf-printer

npm version npm downloads bundle JSDocs License

English | 繁體中文



A lightweight tool for printing Vue components to PDF.

✨ Features

Inspired by vue3-print-nb, but:

  • More lightweight
  • Supports Typescript
  • No need to render the component to be printed, directly convert the component to PDF

🚀 Usage

.preview()

Opens a new window to preview the printed PDF.

.print()

Executes the print.

Example

<script setup lang="ts">
import { h, onMounted, shallowRef } from 'vue'
import { VuePdfPrinter } from 'vue-pdf-printer'

import Com from './components/Com.vue'

const printer = shallowRef<VuePdfPrinter>()

onMounted(() => {
  // use h to pass props into the component, or you can pass the component directly without using h.
  PDF.value = new VuePdfPrinter(
    h(Com, { title: 'some title' }),
    {
      title: 'file title',
    },
  )

  // open print window
  printer.value.print()
})
</script>

📄 License

MIT License © 2024-PRESENT CofCat

About

A lightweight tool for printing Vue components to PDF.

License:MIT License


Languages

Language:TypeScript 75.2%Language:Vue 12.2%Language:HTML 10.3%Language:JavaScript 1.2%Language:CSS 1.1%