Skip to content

Commit

Permalink
began working on improving client side PDF export
Browse files Browse the repository at this point in the history
  • Loading branch information
zoey-kaiser committed Mar 4, 2024
1 parent f67f992 commit 3de5e9a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
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>

0 comments on commit 3de5e9a

Please sign in to comment.