Welcome to the Vue PDF Viewer (VPV) starter toolkit! This repository provides a comprehensive guide on how to use VPV with VitePress via the Markdown and TypeScript. This repo showcases how VPV can be integrated and rendered as part of a VitePress project.
To get started, please clone this repo to your local machine and install the dependencies:
git clone https://github.com/your-username/starter-vpv-vitepress.git
cd starter-vpv-vitepress
npm install
-
Clone the Repository: If you haven't already, clone the repository and navigate into the project directory.
git clone https://github.com/your-username/starter-vpv-vitepress.git cd starter-vpv-vitepress
-
Install Dependencies: Install the necessary dependencies using npm or yarn
npm install # or yarn install # or pnpm install # or bun install
Remark: For pnpm
, there is a bit more configuration required which can be found here.
This repo includes an example project to demonstrate how to use VPV. To run the example project:
-
Serve the Application: Use the following command to start the development server
npm run docs:dev # or yarn docs:dev # or pnpm run docs:dev # or bun run docs:dev
-
Open in Browser: Open your browser and navigate to
http://localhost:5173
(or the port specified in your terminal) to see the example project in action
Once the example project is running, you can explore the source code to see how the VPV component is integrated. Here is a brief overview:
-
Import the component: Import the desired VPV component into your
md
fileimport { useData, defineClientComponent } from 'vitepress' const VPdfViewer = defineClientComponent(() => { return import('@vue-pdf-viewer/viewer').then(({ VPdfViewer }) => VPdfViewer) })
-
Use the component in the template: Add the VPV component to your template section
<template> <div :style="{ width: '1028px', height: '700px'}"> <VPdfViewer src="https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf" /> </div> </template>
-
Ensure the configuration: Add the following code to your
.vitepress/config.ts
import { defineConfig } from 'vitepress' export default defineConfig({ // ... themeConfig: { // ... }, vite: { ssr: { noExternal: ['pdfjs-dist', '@vue-pdf-viewer/viewer'] } } })
For more examples, please refer to the docs/*.md
files in this repository:
- Desktop View
- Mobile View
Remark: If you would like more examples, feel free open an issue.
For more configurations, please check the documentation site.
Thank you for using Vue PDF Viewer! We hope this toolkit helps you build amazing VitePress applications. If you have any questions or need further assistance on this example, please feel free to open an issue. Happy coding!