Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions playground/components/TestStage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<PDFPage>
<h1>
Test
</h1>
</PDFPage>
</template>
23 changes: 23 additions & 0 deletions playground/pages/test.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script lang="ts" setup>
import { exportToPDF } from '#imports'

const pdfSection = ref<HTMLElement | null>(null)
</script>

<template>
<div>
<div>
Export The page:
<button
style="border-radius: 0; font-size: 20px; cursor: pointer"
@click="exportToPDF('pdf_export.pdf', pdfSection as HTMLElement, undefined, {html2canvas: {scale: 0.7, useCORS: true}})"
>
Generate normal PDF
</button>
</div>
<hr>
<div ref="pdfSection">
<TestStage />
</div>
</div>
</template>
9 changes: 8 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineNuxtModule, createResolver, addImportsDir } from '@nuxt/kit'
import { defineNuxtModule, createResolver, addImportsDir, addComponent } from '@nuxt/kit'
import { defu } from 'defu'
import type { ModuleOptions } from './runtime/types'

Expand Down Expand Up @@ -48,5 +48,12 @@ export default defineNuxtModule<ModuleOptions>({
// Step 2: Inject Client side composables to create pdfs from vue components
const composables = resolver.resolve('./runtime/composables')
addImportsDir(composables)

// Step 3: Inject PDF Components
addComponent({
name: 'PDFPage',
export: 'PDFPage',
filePath: resolver.resolve('runtime/components/PDFPage.vue')
})
}
})
6 changes: 6 additions & 0 deletions src/runtime/components/PDFPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<div>
<h1>Test</h1>
<slot />
</div>
</template>