### Install vue-pdf with bun
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/docs/intro/getting-started.md
Install the vue-pdf package as a development dependency using bun.
```sh
$ bun add -D @ceereals/vue-pdf
```
--------------------------------
### Install vue-pdf with yarn
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/docs/intro/getting-started.md
Install the vue-pdf package as a development dependency using yarn.
```sh
$ yarn add -D @ceereals/vue-pdf
```
--------------------------------
### Install Vue PDF
Source: https://github.com/ceereals/vue-pdf/blob/main/README.md
Install the Vue PDF package using npm. This is the first step before using the library.
```bash
npm install @ceereals/vue-pdf
```
--------------------------------
### Install vue-pdf with pnpm
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/docs/intro/getting-started.md
Install the vue-pdf package as a development dependency using pnpm.
```sh
$ pnpm add -D @ceereals/vue-pdf
```
--------------------------------
### Install vue-pdf with npm
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/docs/intro/getting-started.md
Install the vue-pdf package as a development dependency using npm.
```sh
$ npm add -D @ceereals/vue-pdf
```
--------------------------------
### Vue PDF Web Usage
Source: https://github.com/ceereals/vue-pdf/blob/main/README.md
Example of using Vue PDF in a web browser. It demonstrates rendering a simple PDF document with text.
```html
Hello, Vue PDF!
```
--------------------------------
### Vue PDFPrint Component Example
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/browser-api.md
Create a print link for client-side generated documents with the PDFPrint component. Customize the button's label using the #label slot.
```vue
Print Now!
...
```
--------------------------------
### Vue PDFDownloadLink Component Example
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/browser-api.md
Implement a download link for client-side generated documents using the PDFDownloadLink component. Customize the download file name and the link's label using slots.
```vue
Download Now!
...
```
--------------------------------
### Vue PDF Node.js Usage
Source: https://github.com/ceereals/vue-pdf/blob/main/README.md
Example of using Vue PDF on the server-side with Node.js. It renders a PDF document to a file.
```javascript
import { Document, Page, Text, View, renderToFile } from "@ceereals/vue-pdf";
import { defineComponent, h } from "@vue/runtime-core";
import fs from "fs";
const DocumentTemplate = defineComponent(() => {
return () => (
h(Document, [
h(Page, { size: "A4" }, [
h(
View, { style: viewStyle },
[
h(
Text, { style: textStyle },
"Hello, Vue PDF!",
),
],
),
]),
])
)
})
const stream = renderToFile(DocumentTemplate,'document.pdf');
```
--------------------------------
### Vue PDFViewer Component Example
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/browser-api.md
Use the PDFViewer component to embed an iframe PDF viewer for client-side generated documents. Configure viewer options via query parameters and disable the provide bridge if needed.
```vue
...
```
--------------------------------
### Create a basic PDF document in Vue
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/docs/intro/getting-started.md
Define a simple PDF document structure using vue-pdf components. Ensure the Document component is the root and only contains Page components.
```vue
Hello, Vue PDF!
```
```ts
import { Document, Page, Text, View } from "@ceereals/vue-pdf";
import { defineComponent, h, reactive } from "vue";
export default defineComponent(() => {
const viewStyle = reactive({
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
height: "100%",
});
const textStyle = reactive({
fontSize: 24,
});
return () =>
h(Document, [
h(Page, { size: "A4" }, [
h(
View,
{
style: viewStyle,
},
[
h(
Text,
{
style: textStyle,
},
"Hello, Vue PDF!",
),
],
),
]),
]);
});
```
```tsx
import { Document, Page, Text, View } from "@ceereals/vue-pdf";
import { defineComponent, reactive } from "vue";
export default defineComponent(() => {
const viewStyle = reactive({
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
height: "100%",
});
const textStyle = reactive({
fontSize: 24,
});
return () => (
Hello, Vue PDF!
);
});
```
--------------------------------
### Render PDF to File with Node.js
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/docs/intro/getting-started.md
Utilize the `renderToFile` function in Node.js to generate a PDF file. This function returns a Promise that resolves to a readable stream once the file is written.
```javascript
import { renderToFile } from "@ceereals/vue-pdf";
import HelloWorldDocument from "./HelloWorldDocument.ts";
await renderToFile(HelloWorldDocument, "hello-world.pdf");
```
```javascript
import { h } from "vue";
import { renderToFile } from "@ceereals/vue-pdf";
import HelloWorldDocument from "./HelloWorldDocument.ts";
await renderToFile(h(HelloWorldDocument, /** props */), "hello-world.pdf");
```
--------------------------------
### renderToFile
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/node-api.md
Renders a Vue PDF document to a specified file path.
```APIDOC
## `renderToFile`
### Description
Renders a Vue PDF document to a specified file path.
### Method
`renderToFile(document: Component, outputPath: string, options?: RenderOptions)`
### Parameters
- **document** (Component) - Required - The Vue component representing the PDF document.
- **outputPath** (string) - Required - The path where the PDF file will be saved.
- **options** (RenderOptions) - Optional - Additional rendering options.
### Request Example
```ts
import { renderToFile } from '@ceereals/vue-pdf/node'
import HelloWorldDocument from './HelloWorldDocument.ts'
await renderToFile(HelloWorldDocument, 'output.pdf')
```
### Request Example with Props
```ts
import { h } from 'vue'
import { renderToFile } from '@ceereals/vue-pdf/node'
import HelloWorldDocument from './HelloWorldDocument.ts'
await renderToFile(h(HelloWorldDocument, {/** props */}), 'output.pdf')
```
```
--------------------------------
### View Component
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/components-api.md
A fundamental component for building the UI, designed to be nested and can contain other views.
```APIDOC
## ``
The most fundamental component for building a UI and is designed to be nested inside other views and can have 0 to many children.
- **Props**
<<< ../../src/components/index.ts#ViewProps
```
--------------------------------
### Using PDFSuspense for Async Content
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/components-api.md
Demonstrates how to use PDFSuspense to handle asynchronous content loading within a PDF document. The fallback slot displays 'Loading...' while the async content is being fetched.
```vue
Loading...
```
```vue
{{ text }}
```
--------------------------------
### usePdf Composable - Script Usage with Runtime Core
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/browser-api.md
Generate a PDF from a script using the usePdf composable and Vue's runtime core. This allows for PDF generation in environments where a full Vue app might not be present, such as Node.js.
```ts
import { h } from '@vue/runtime-core'
import { usePdf } from '@ceereals/vue-pdf'
import HelloWorldDocument from './HelloWorldDocument.vue'
const { url } = await usePdf(
h(HelloWorldDocument, {
/** props */
})
)
```
--------------------------------
### Render PDF in Browser with usePdf
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/docs/intro/getting-started.md
Use the `usePdf` composable to render a PDF document directly in the browser. It accepts a Vue component or a render function. The generated URL can be used in an iframe.
```vue
```
```vue
```
--------------------------------
###
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/browser-api.md
A component that renders a download link for client-side generated PDF documents. It supports custom labels via slots and emits events.
```APIDOC
##
### Description
Download link for client-side generated documents.
### Props
Refer to the `PDFDownloadLinkProps` definition in `../../src/components/index.ts` for available props.
### Slots
Refer to the `PDFDownloadLinkSlots` definition in `../../src/components/index.ts` for available slots.
### Events
Refer to the `PDFDownloadLinkEvents` definition in `../../src/components/index.ts` for available events.
### Example
```vue
Download Now!
...
```
```
--------------------------------
### renderToBuffer
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/node-api.md
Renders a Vue PDF document to a buffer.
```APIDOC
## `renderToBuffer`
### Description
Renders a Vue PDF document directly into a Node.js Buffer.
### Method
`renderToBuffer(document: Component, options?: RenderOptions): Promise`
### Parameters
- **document** (Component) - Required - The Vue component representing the PDF document.
- **options** (RenderOptions) - Optional - Additional rendering options.
### Response
- **Buffer** - A Buffer containing the PDF data.
### Request Example
```ts
import { renderToBuffer } from '@ceereals/vue-pdf'
import HelloWorldDocument from './HelloWorldDocument.ts'
import fs from 'fs'
const buffer = await renderToBuffer(HelloWorldDocument)
fs.writeFileSync('output.pdf', buffer)
```
### Request Example with Props
```ts
import { h } from 'vue'
import { renderToBuffer } from '@ceereals/vue-pdf'
import HelloWorldDocument from './HelloWorldDocument.ts'
import fs from 'fs'
const buffer = await renderToBuffer(h(HelloWorldDocument, {/** props */}))
fs.writeFileSync('output.pdf', buffer)
```
```
--------------------------------
### renderToStream
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/node-api.md
Renders a Vue PDF document to a readable stream.
```APIDOC
## `renderToStream`
### Description
Renders a Vue PDF document to a readable stream, allowing for piping to other destinations.
### Method
`renderToStream(document: Component, options?: RenderOptions): Promise`
### Parameters
- **document** (Component) - Required - The Vue component representing the PDF document.
- **options** (RenderOptions) - Optional - Additional rendering options.
### Response
- **ReadableStream** - A readable stream of the generated PDF.
### Request Example
```ts
import { renderToStream } from '@ceereals/vue-pdf'
import HelloWorldDocument from './HelloWorldDocument.ts'
import fs from 'fs'
const stream = await renderToStream(HelloWorldDocument)
stream.pipe(fs.createWriteStream('output.pdf'))
```
### Request Example with Props
```ts
import { h } from 'vue'
import { renderToStream } from '@ceereals/vue-pdf'
import HelloWorldDocument from './HelloWorldDocument.ts'
import fs from 'fs'
const stream = await renderToStream(h(HelloWorldDocument, {/** props */}))
stream.pipe(fs.createWriteStream('output.pdf'))
```
```
--------------------------------
### Note Component
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/components-api.md
A Vue component for displaying note annotations within the PDF document.
```APIDOC
## ``
A Vue component for displaying a note annotation inside the document.
- **Props**
<<< ../../src/components/index.ts#NoteProps
```
--------------------------------
### usePdf Composable - Async PDF URL
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/browser-api.md
Fetch the PDF URL asynchronously using the usePdf composable. This is useful for directly linking to or displaying the generated PDF.
```vue
Download PDF
```
--------------------------------
### usePdf()
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/browser-api.md
A Vue composable function for generating PDF documents on the client-side. It can be used in Vue components or scripts.
```APIDOC
## usePdf()
### Description
Vue composable for generating PDF documents.
### Type
Refer to the `usePdf` type definition in `../../src/composables/usePdf.ts`.
### Example
::: code-group
```vue [MyComponent.vue]
```
```vue [MyAsyncComponent.vue]
Download PDF
```
```ts [MyScript.ts]
import { h } from '@vue/runtime-core'
import { usePdf } from '@ceereals/vue-pdf'
import HelloWorldDocument from './HelloWorldDocument.vue'
const { url } = await usePdf(
h(HelloWorldDocument, {
/** props */
})
)
```
:::
> [!Note]
> You can also use `usePdf` in Node.js and use the Vue reactivity system without needing to create a Vue App.
```
--------------------------------
### Image Component
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/components-api.md
A Vue component for displaying JPG or PNG images from network, local sources (Node only), or base64 encoded strings.
```APIDOC
## ``
A Vue component for displaying network or local (Node only) JPG or PNG images, as well as base64 encoded image strings.
- **Props**
<<< ../../src/components/index.ts#ImageProps
```
--------------------------------
###
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/browser-api.md
A component that provides a print link for client-side generated PDF documents. It allows for custom labels through slots and emits events.
```APIDOC
##
### Description
Print link for client-side generated documents.
### Props
Refer to the `PDFPrintProps` definition in `../../src/components/index.ts` for available props.
### Slots
Refer to the `PDFPrintSlots` definition in `../../src/components/index.ts` for available slots.
### Events
Refer to the `PDFPrintEvents` definition in `../../src/components/index.ts` for available events.
### Example
```vue
Print Now!
...
```
```
--------------------------------
### usePdf Composable - Execute PDF Generation
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/browser-api.md
Use the usePdf composable in Vue components to generate PDF documents. The 'execute' function can be called to trigger the generation process, optionally with a reactive flag.
```vue
```
--------------------------------
### Render Vue Component to PDF Stream
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/node-api.md
Utilize `renderToStream` for generating PDF output as a stream, which can then be piped to a file or another stream destination. This is efficient for large documents or when processing needs to happen incrementally.
```typescript
import { renderToStream } from '@ceereals/vue-pdf'
import HelloWorldDocument from './HelloWorldDocument.ts'
const stream = await renderToStream(HelloWorldDocument)
stream.pipe(fs.createWriteStream('output.pdf'))
```
```typescript
import { h } from 'vue'
import
import { renderToStream } from '@ceereals/vue-pdf'
import HelloWorldDocument from './HelloWorldDocument.ts'
const stream = await renderToStream(h(HelloWorldDocument, {/** props */}))
stream.pipe(fs.createWriteStream('output.pdf'))
```
--------------------------------
###
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/browser-api.md
An iframe PDF viewer component for client-side generated documents. It accepts props to customize its behavior and appearance.
```APIDOC
##
### Description
Iframe PDF viewer for client-side generated documents.
### Props
Refer to the `PDFViewerProps` definition in `../../src/components/index.ts` for available props.
### Example
```vue
...
```
```
--------------------------------
### Render Vue Component to PDF File
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/node-api.md
Use `renderToFile` to generate a PDF directly from a Vue component. This is suitable for saving the PDF to a specified file path.
```typescript
import { renderToFile } from '@ceereals/vue-pdf/node'
import HelloWorldDocument from './HelloWorldDocument.ts'
await renderToFile(HelloWorldDocument, 'output.pdf')
```
```typescript
import { h } from 'vue'
import { renderToFile } from '@ceereals/vue-pdf/node'
import HelloWorldDocument from './HelloWorldDocument.ts'
await renderToFile(h(HelloWorldDocument, {/** props */}), 'output.pdf')
```
```typescript
import { Document, Page, Text, View } from "@ceereals/vue-pdf";
import { defineComponent, h, reactive } from "vue";
export default defineComponent(() => {
const viewStyle = reactive({
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
height: "100%",
});
const textStyle = reactive({
fontSize: 24,
});
return () =>
h(Document, [
h(Page, { size: "A4" }, [
h(
View,
{
style: viewStyle,
},
[
h(
Text,
{
style: textStyle,
},
"Hello, Vue PDF!",
),
],
),
]),
]);
});
```
--------------------------------
### Canvas Component
Source: https://github.com/ceereals/vue-pdf/blob/main/docs/reference/components-api.md
A Vue component for freely drawing any content directly onto the PDF page.
```APIDOC
## `