Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pdf support #6143

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

feat: add pdf support #6143

wants to merge 9 commits into from

Conversation

doouding
Copy link
Member

@doouding doouding commented Jan 29, 2024

New pdf block

pdf block can be rendered in both 'doc' and 'edgeless' modes, where it acts as a child of affine:note and affine:surface respectively.

type PDFProps = {
  sourceId: string;
  annotations: Boxed<Y.Map<unknown>>;
  xywh: SerializedXYWH;
  index: string;
};

export const PDFBlockSchema = defineBlockSchema({
  flavour: 'affine:pdf',
  props: (internalPrimitives): PDFProps => ({
    annotations: internalPrimitives.Boxed(new Workspace.Y.Map()),
    sourceId: '',
    xywh: `[0,0,100,100]`,
    index: 'a0',
  }),
  metadata: {
    version: 1,
    role: 'hub',
    parent: ['affine:surface', 'affine:note'],
  },
  toModel() {
    return new PDFBlockModel();
  },
});

How to load pdf.js

The way of importing PDF.js is determined by the user. The user needs to call the setPDFModule method to tell the blocksuite how to load PDF.js and its plugins.

import { PDFService } from '@blocksuite/blocks';
import pdfWorkerSrc from 'pdfjs-dist/build/pdf.worker.min.mjs?url';

PDFService.setPDFModule([
    () => import('pdfjs-dist'),
    () => import('pdfjs-dist/web/pdf_viewer.mjs').then(m => m.TextLayerBuilder),
    pdfWorkerSrc,
]);

Copy link

vercel bot commented Jan 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blocksuite ❌ Failed (Inspect) Feb 28, 2024 3:11am
blocksuite-docs ❌ Failed (Inspect) Feb 28, 2024 3:11am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

1 participant