Skip to content

Conversation

dakshesh14
Copy link
Contributor

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.

@dakshesh14
Copy link
Contributor 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.

@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
Contributor 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.

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 !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used ResizableFileBlockWrapper, but it made the whole PDF block a bit laggy to resize. I think the issue is with the <embed> tag and not ResizableFileBlockWrapper, since replacing <embed> with a <div> (for testing) removed the lag. What do you suggest I do here?

Adding an option to resize height sounds good, but if that works for you, I’d prefer to handle it in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Decided to revert changes related to resizing to make the PR short. We can look into resizing in a separate PR along with the height resizing option.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure either.

@dakshesh14
Copy link
Contributor Author

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

@AntoLC AntoLC self-requested a review September 1, 2025 09:00
@dakshesh14 dakshesh14 force-pushed the feat/pdf-upload branch 2 times, most recently from 49aa5ae to b28786a Compare September 20, 2025 12:10
@dakshesh14
Copy link
Contributor Author

Hey @AntoLC,

I’ve addressed all your review comments and also resolved the merge conflict. I decided to handle PDF resizing in a separate PR to keep this one focused and shorter.

Could you please take another look when you get a chance?

dakshesh14 and others added 2 commits September 26, 2025 17:15
Added pdf block in the editor.

Signed-off-by: dakshesh14 <[email protected]>
The way we were handling the antivirus upload loader
was not optimal, it didn't work well with the pdf
embed block. We created a dedicated upload loader
block, it will replace the previous implementation,
it is more Blocknote idiomatic and will work
better with any type of upload files.
@AntoLC AntoLC linked an issue Sep 26, 2025 that may be closed by this pull request
@AntoLC AntoLC merged commit cc4bed6 into suitenumerique:main Sep 26, 2025
21 of 22 checks passed
@AntoLC
Copy link
Collaborator

AntoLC commented Sep 26, 2025

@dakshesh14 I took the freedom to finalize the PR to fit our needs (test e2e, manage loading upload with antivirus..).

Thank you very much for this contribution, it is a very nice feature 🎉 !!
If you feel motivated to try to implement a height resizing, feel free to propose a contribution.

Thanks 🙏

@dakshesh14 dakshesh14 deleted the feat/pdf-upload branch September 26, 2025 15:40
@dakshesh14
Copy link
Contributor Author

I totally understand - explaining those changes can often be harder than just fixing them directly, especially since you already have the full context of the system.

I’m really glad you liked the feature! This PR ended up being bigger than I anticipated, so next time I’ll ensure that my changes are more focused and concise to make reviewing easier.

I truly appreciate your efforts and patience throughout the process.

Thanks again, @AntoLC and @virgile-dev 🙏

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.

✨ Add a PDF reader in docs
3 participants