-
Notifications
You must be signed in to change notification settings - Fork 5
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
Experimental pdf exports v2 #639
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: MTRNord <[email protected]>
Signed-off-by: MTRNord <[email protected]>
|
@@ -40,17 +40,74 @@ export function image(element: ImageElement, base64content: string): Content { | |||
}; | |||
} | |||
|
|||
function preprocessSvg(element: ImageElement, svg: string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Canvas requires there to be a width and height on the svg element. Otherwise it wont draw it.
const svgString = atob(svg); | ||
|
||
// We lied in the past about the mimetype, so we need to check if the svg is actually an svg and otherwise return the original string | ||
if (!svgString.startsWith('<svg')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apaprently we had nwb files which lied and marked png files as svg. This is a sanity check for it...
} | ||
|
||
// If we now end up with a png or jpeg image we can return it early | ||
if (element.mimeType === 'image/png' || element.mimeType === 'image/jpeg') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the short-circuit for files which lied about being an svg.
> | ||
{element.text && ( | ||
<Text | ||
x={element.position.x + element.width / 2 - textWidth / 2} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason (bug?) react-sdk doesnt seem to position this correctly inside the rectangle so i had to do it myself.
); | ||
})} | ||
</Svg> | ||
{imageElements.map((element, j) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
react-pdf will not work if the image is inside of the svg.
Font.registerEmojiSource({ | ||
format: 'png', | ||
// TODO: Replace with something we serve ourselves | ||
url: 'https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/72x72/', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Replace with something hosted by us inside of the neoboard.
|
||
import { renderPDF } from './pdf.local'; | ||
|
||
if (import.meta.hot) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a whole bunch of hacking because HMR for react in vite currently is totally messed up with webworkers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes it explicitly error out which is intended here. Otherwise it would crash the webworker when using react.
import { WhiteboardDocumentExport } from '../../../state/export/whiteboardDocumentExport'; | ||
|
||
const renderPDF = async (exportData: WhiteboardDocumentExport) => { | ||
const { pdf, Font } = await import('@react-pdf/renderer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can not use any file level imports for things that interact with react in anyway as this will break HMR on the webworker due to vite bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ensures the bundles are split correctly across the 2 worlds
Signed-off-by: MTRNord <[email protected]>
Signed-off-by: MTRNord <[email protected]>
723eb8d
to
56153b3
Compare
@@ -23,7 +23,8 @@ | |||
"react-redux": "^9.1.2" | |||
}, | |||
"resolutions": { | |||
"fork-ts-checker-webpack-plugin": "^6.5.3" | |||
"fork-ts-checker-webpack-plugin": "^6.5.3", | |||
"@vitejs/plugin-react-swc": "git+https://github.com/vitejs/vite-plugin-react-swc.git" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required as we require vitejs/vite-plugin-react-swc@beb09db
Signed-off-by: MTRNord <[email protected]>
Signed-off-by: MTRNord <[email protected]>
Signed-off-by: MTRNord <[email protected]>
…omewhere Signed-off-by: MTRNord <[email protected]>
…Text stuff Signed-off-by: MTRNord <[email protected]>
Signed-off-by: MTRNord <[email protected]>
Signed-off-by: MTRNord <[email protected]>
Signed-off-by: MTRNord <[email protected]>
Untitled-58.pdf
TODOs:
I am for now blaming it on using a different font in the pdf vs on the svg canvasThis was partially the calculation code being still buggy but also SVG Text doesn't have a way to wrap diegomura/react-pdf#2971 seems to be causing this.For our internal tracking
✔️ Checklist
Signed-off-by
line in the message (more info).