### 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 ``` -------------------------------- ### 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 ``` -------------------------------- ### 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 ``` -------------------------------- ### 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 ``` ```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 ``` ```vue ``` -------------------------------- ### 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