Skip to content

Conversation

dakshesh14
Copy link

Purpose

Added an option for users to upload and preview PDF files in the editor. This PR addresses #348. It is a duplicate of PR-795 because I couldn't reopen the PR as I lost my fork.

pdf-embed.webm
mobile-view-demo

Proposal

Added the option for users to upload and preview PDF files within the editor.

Description:

  • When a user types '/' on their keyboard, they can find an option called "PDF," which allows them to upload or embed PDF files.

Changed content disposition as inline so that pdf is not downloaded automatically.

Signed-off-by: dakshesh14 <65905942+dakshesh14@users.noreply.github.com>
Added pdf block in the editor.

Signed-off-by: dakshesh14 <65905942+dakshesh14@users.noreply.github.com>
Moved drag handler logic to a hook to make component dumb.

Signed-off-by: dakshesh14 <65905942+dakshesh14@users.noreply.github.com>
Made docx and pdf export mapper for the newly added pdf block

Signed-off-by: dakshesh14 <65905942+dakshesh14@users.noreply.github.com>
@dakshesh14
Copy link
Author

Hey team,

This is a duplicate of PR-795, since I couldn’t reopen the original after losing the fork.

I’d appreciate the maintainers’ input on a few points where the implementation could be improved:

  • PDF preview: Should we use react-pdf or another library for better compatibility and user experience?
  • Nginx config change: The current approach requires modifying Nginx, which might not be acceptable. I’m open to alternatives.
  • Access to non-public PDFs: Currently, non-public PDFs can’t be previewed/downloaded. A solution here might also address point (2).

Looking forward to your feedback and happy to adjust the implementation accordingly.

Added pr number in changelog

Signed-off-by: dakshesh14 <65905942+dakshesh14@users.noreply.github.com>
@virgile-dev
Copy link
Collaborator

Hey @dakshesh14 !
great to see you were able to give it a second shot. @AntoLC is on vacation right now.
Once he is back he’ll able to review your PR.
sorry for the delay and thanks for your contribution

@dakshesh14
Copy link
Author

Hey @virgile-dev, happy to be back! No problem at all - I’ll wait for @AntoLC to return and review the PR. Thanks for keeping me posted.

@AntoLC AntoLC added frontend feature add a new feature labels Aug 28, 2025
Copy link
Collaborator

@AntoLC AntoLC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution, it is a great feature ! 🎉

Feel free to ask me if you need more details about the comments.

@@ -6,6 +6,8 @@ export * from './headingPDF';
export * from './imageDocx';
export * from './imagePDF';
export * from './paragraphPDF';
export * from './pdfDocx';
export * from './pdfPdf';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export * from './pdfPdf';
export * from './pdfPDF';

<AddFileButton
block={block}
editor={editor as FileBlockEditor}
buttonText="Add PDF"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be translatable.

showPreview: { default: true },
previewWidth: { default: undefined, type: 'number' },
},
isFileBlock: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To target only pdf files:

Suggested change
isFileBlock: true,
isFileBlock: true,
fileBlockAccept: ['application/pdf'],

block={block}
editor={editor as FileBlockEditor}
buttonText="Add PDF"
buttonIcon={<Icon iconName="upload" $size="18px" />}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default the size seems to be "24px", it is the size on the others blocks, if you put lower directly on the icon, the icon will look not centered anymore.
If you want to put it at "18px", you should modify ".bn-add-file-button-icon".

Suggested change
buttonIcon={<Icon iconName="upload" $size="18px" />}
buttonIcon={<Icon iconName="upload" />}

Comment on lines +47 to +62
const { wrapperRef, pdfWidth, handlePointerDown } = usePdfResizer(
block.props.previewWidth ?? 100,
handleResizeEnd,
);

return (
<div ref={contentRef} className="bn-file-block-content-wrapper">
{pdfUrl === '' ? (
<AddFileButton
block={block}
editor={editor as FileBlockEditor}
buttonText="Add PDF"
buttonIcon={<Icon iconName="upload" $size="18px" />}
/>
) : (
<FileBlockWrapper block={block} editor={editor as FileBlockEditor}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should leverage ResizableFileBlockWrapper, it will simplify your component a lot.
ResizableFileBlockWrapper includes the resizing logic, plus it includes the part when the url is not defined yet.
You can see how to use it here: https://github.com/TypeCellOS/BlockNote/blob/7a66f11fd8a21ce3c1ffcb87590ae44b7f877ed6/packages/react/src/blocks/ImageBlockContent/ImageBlockContent.tsx

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be in another PR, but make ResizableFileBlockWrapper sizable on height as well will be great !

<Box
$display="flex"
$align="center"
$justify="center"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep some consistency with the existing (try to include a file "Embedded File"):

Suggested change
$justify="center"
className="bn-file-name-with-icon"
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to have some drag and drop issue with the embed tag, not sure why.

-.Docs.1.webm

Comment on lines +11 to +30
<View
style={{
marginVertical: 10,
padding: 10,
border: '1px solid #ccc',
borderRadius: 4,
backgroundColor: '#f9f9f9',
}}
>
<Text style={{ fontSize: 12, fontWeight: 'bold', marginBottom: 5 }}>
📄 {pdfName}
</Text>
{pdfUrl && (
<Text style={{ fontSize: 10, color: '#666' }}>Source: {pdfUrl}</Text>
)}
<Text style={{ fontSize: 10, color: '#999', marginTop: 5 }}>
[PDF content cannot be embedded in exported PDF]
</Text>
</View>
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is not supported we should just fallback on what is made already, same for "Docx":
https://github.com/TypeCellOS/BlockNote/blob/7a66f11fd8a21ce3c1ffcb87590ae44b7f877ed6/packages/xl-pdf-exporter/src/pdf/defaultSchema/blocks.tsx#L205-L218

image

It is on the roadmap to improve the design export.

},
aliases: ['pdf', 'document', 'embed', 'file'],
group,
icon: <Icon iconName="upload" $size="18px" />,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about picture_as_pdf icon instead ?

Comment on lines +24 to +26
proxy_hide_header Content-Disposition;
add_header Content-Disposition "inline";

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure to understand why it is necessary, seems to work fine with the embed tag without changing to "inline" ?
Is there a browser where you get a problem maybe ?

@dakshesh14
Copy link
Author

Hi @AntoLC, thank you for your reviews! I will work on these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature add a new feature frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants