English | 繁體中文
A lightweight tool for printing Vue components to PDF.
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
Opens a new window to preview the printed PDF.
Executes the print.
<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>