These guides have the following sections:
git clone git@github.com:foxitsoftware/FoxitPDFSDKForWeb-Vue3-Example.git vue3-websdkcd vue3-websdk
npm install3. Update the licenseSN and licenseKey values in vue3-websdk/src/App.vue with your own licenseSN and licenseKey that you received from sales
npm run devNavigate to vue3-websdk/public/FoxitPDFSDKForWeb/server/snapshot, and execute:
npm install
npm run startStarting from FoxitPDFSDK for Web version 10.0.0, since service worker is used, it is necessary to add this field in the HTTP response header of the Service Worker script. Its value is the maximum allowed scope path:
Service-Worker-Allowed /;If you are using Nginx as your server, you can add the Service-Worker-Allowed response header by modifying the Nginx configuration file. Below is an example configuration:
server {
location /sw.js {
add_header Service-Worker-Allowed /;
}
}If you use Webpack Dev Server for local development, you can add Service-Worker-Allowed response headers by configuring devServer. The following is a configuration example:
// webpack.config.js
module.exports = {
// 其他配置
devServer: {
headers: {
'Service-Worker-Allowed': '/'
}
}
};Execute the command npm init vue@latest and follow the wizard to complete the setup:
- Project name: -> vue3-websdk
- Add TypeScript? -> No
- Add JSX Support? -> No
- Add Vue Router for Single Page Application development? -> No
- Add Pinia for state management? -> No
- Add Vitest for Unit testing? -> No
- Add Cypress for both Unit and End-to-End testing? -> No
- Add ESLint for code quality? -> No
- Add Prettier for code formatting? -> No
cd vue3-websdk
npm install
npm install @foxitsoftware/foxit-pdf-sdk-for-web-library
npm install -D rollup-plugin-copy<script setup>
import '@foxitsoftware/foxit-pdf-sdk-for-web-library/lib/UIExtension.css';
import * as UIExtension from '@foxitsoftware/foxit-pdf-sdk-for-web-library/lib/UIExtension.full.js';
import preloadJrWorker from '@foxitsoftware/foxit-pdf-sdk-for-web-library/lib/preload-jr-worker.js';
import {onMounted} from 'vue';
onMounted(() => {
const licenseSN = 'xxx';
const licenseKey = 'xxx';
const readyWorker = preloadJrWorker({
workerPath: '/FoxitPDFSDKForWeb/lib/',
enginePath: '../lib/jr-engine/gsdk',
fontPath: 'http://webpdf.foxitsoftware.com/webfonts/',
licenseSN: licenseSN,
licenseKey: licenseKey
});
const PDFUI = UIExtension.PDFUI;
const pdfui = new PDFUI({
viewerOptions: {
libPath: '/FoxitPDFSDKForWeb/lib',
jr: {
readyWorker: readyWorker
}
},
renderTo: '#pdf-ui',
appearance: UIExtension.appearances.adaptive,
fragments: [],
addons: UIExtension.PDFViewCtrl.DeviceInfo.isMobile ?
'/FoxitPDFSDKForWeb/lib/uix-addons/allInOne.mobile.js':
'/FoxitPDFSDKForWeb/lib/uix-addons/allInOne.js'
});
});
</script>
<template>
<div class="fv__ui-nav">
<div class="fv__ui-nav-logo">
<i class="fv__icon-logo"></i>
</div>
</div>
<div id="pdf-ui"></div>
</template>
<style scoped>
#pdf-ui {
top: 40px;
bottom: 0;
position: absolute;
width: 100vw;
}
</style>
4. Update the licenseSN and licenseKey values in vue3-websdk/src/App.vue with your own licenseSN and licenseKey that you received from sales
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'node:path';
import { normalizePath } from 'vite';
import copy from 'rollup-plugin-copy'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
copy({
targets: [
{
src: normalizePath(path.resolve(__dirname, 'node_modules/@foxitsoftware/foxit-pdf-sdk-for-web-library/lib')),
dest: normalizePath(path.resolve(__dirname, 'public/FoxitPDFSDKForWeb'))
},
{
src: normalizePath(path.resolve(__dirname, 'node_modules/@foxitsoftware/foxit-pdf-sdk-for-web-library/server')),
dest: normalizePath(path.resolve(__dirname, 'public/FoxitPDFSDKForWeb'))
}
],
hook: 'buildStart'
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
proxy: {
'/snapshot': 'http://localhost:3002',
},
headers: {
'Service-Worker-Allowed': '/'
}
}
})- import './assets/main.css'
+ // import './assets/main.css'
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')npm run devNavigate to vue3-websdk/public/FoxitPDFSDKForWeb/server/snapshot, and execute:
npm install
npm run start1. After autoprefixer is used, a large number of logs are generated on the console. How can I solve this problem?
Remove the import '@foxitsoftware/foxit-pdf-sdk-for-web-library/lib/UIExtension.css'; from App.vue,Add <link rel="stylesheet" href="/FoxitPDFSDKForWeb/lib/UIExtension.css"> to index.html.