@univerjs-pro/pdfs-ui
Canvas rendering and editing UI for Web SDK PDF units, with desktop and mobile workbenches.
import { UniverPdfsUIPlugin } from '@univerjs-pro/pdfs-ui'import '@univerjs-pro/pdfs-ui/lib/index.css'univer.registerPlugin(UniverPdfsUIPlugin, { editor: { enabled: true }, thumbnailWorkerURL: new Worker(new URL('./pdf-thumbnail.worker.ts', import.meta.url), { type: 'module' }),})editor.enabled defaults to true and controls whether the plugin registers PDF editing commands, clipboard handling, the ribbon, the inspector, and thumbnail actions. thumbnailWorkerURL accepts a string, URL, or Worker for OffscreenCanvas thumbnail rendering.
Create the worker entry referenced above:
import { UniverPdfsUIWorkerPlugin } from '@univerjs-pro/pdfs-ui/worker'import { Univer } from '@univerjs/core'const univer = new Univer()univer.registerPlugin(UniverPdfsUIWorkerPlugin)Mobile workbench
Register UniverMobileUIPlugin, UniverDocsMobileUIPlugin, and UniverPdfsMobileUIPlugin for touch editing. The PDF plugin opens a page overview and lets the user tap a page to edit it. Pass { editor: { enabled: false } } to open the read-only viewer with page navigation and zoom. See the mobile installation example.
To zoom an open PDF from application code, import PdfSetZoomRatioOperation from this package and call univerAPI.executeCommand(PdfSetZoomRatioOperation.id, { unitId, zoomRatio: 1.5 }). Omit unitId to target the active PDF. The operation returns false while the page organizer is open.
Menu configuration
Configure the shared Ribbon through UniverUIPlugin's menu and ribbonType options. They are not options of UniverPdfsUIPlugin. For example, pdf.menu.tool.highlight and pdf.menu.tool.ink accept sibling order and Ribbon gridLayout overrides.
Import @univerjs/ui/facade to use FUniver.updateMenuConfig() at runtime. createMenu() and createSubmenu() also accept placement options. See the PDF menu guide for initialization and update examples.
The PDF Ribbon is registered only while editing is enabled. menu overrides do not enable it when editor.enabled is false.
Entry Points
- Locale:
@univerjs-pro/pdfs-ui/locale/* - Style:
@univerjs-pro/pdfs-ui/lib/index.css - Worker plugin:
UniverPdfsUIWorkerPluginfrom@univerjs-pro/pdfs-ui/worker
The root entry also exports renderPdfPageToCanvas for rendering a PDF page into an existing canvas. See the PDF UI overview.
이 가이드는 어떠셨나요?