-
-
Notifications
You must be signed in to change notification settings - Fork 906
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
Scaling SVG performance #138
Comments
Hey @halvard-cognite, Should you want to create your own scaling solution, you will have to overwrite default styles indeed. I don't think I'm planning to change this as I believe vast majority will actually benefit from max-width. Speaking of performance, indeed that's pretty idiotic to cause re-render each time. I'll improve its performance in incoming version 3.0 :) |
Improvement has been merged; 3.0.0-alpha.2 is the first version that has the fix. Let me know what you think! Note: To use alpha version for testing purposes, you can run |
Thats awesome! Thanks for the quick response :) I'm perfectly fine with overriding a style that is useful for most people. But I might be misunderstanding something, is it possible to scale the document without changing the max-width of the svg? The only other option i can think of is to dynamically change the size of the parent container. |
Hmmm. Hope I understand correctly what you want to achieve. You can pass You can also change CSS width using JavaScript, or just the width attribute. Mind you, the latter would not work for canvas rendering. |
I think I might be misunderstanding something basic about this. Is the scaling not supposed to be used as a zoom feature? Maybe adding a zoom example to the docs would be a good idea, I think that would be something a lot of people would want to implement. |
React-PDF is not a fully blown PDF reader, it's only a bridge to build one. I have plans to make one, but this is very time consuming process. The simplest zooming solution you can build is some kind of buttons or a dropdown with width values, which then you set to your application state, and then you pass it to |
@wojtekmaj thank you! We have some advanced use-cases for handling pdfs, maybe we can contribute in some way on this. It would be great if any effort we put into it could benefit the community :) |
That would be awesome! |
Hiya, I'm using the latest version and finding that it seems to repaint all the text when I change the page width on pinch. Am I implementing zoom incorrectly, or is it just laggy with pdf.js? |
Depends on what you mean by repaints. If you mean the browser doing the painting - that's entirely expected. You need updated content on the screen after all. If you mean that React Components are updated, that would seem odd. |
I mean that It seems like the react components are rerendered. It's a tricky thing, trying to get a smooth pinch zoom and then at the end of the zoom letting the pdf quality actually enhance. Right now I just track when I'm pinching and don't render the text layer then, but getting a nice interaction with it has been a bit awkward. I have been wishing there were two different widths I could adjust - the page width, which rerenders completely, and some style element on the canvas object or something. |
Repainting PDF on changing zoom is expected, if you are in Canvas mode. Try out SVG mode, as SVGs, unlikes canvas, can be resized without re-painting. You could also play around with rendering high res PDF in Canvas and use transforms to rescale it, but that seems like a lot of work to me. |
Hey,
Thanks for a great library!
I'm trying out the experimental svg rendering, and found it to solve my initial problems with text annotations that render in the wrong place.
However when trying to add a zoom feature that uses scaling, I ran into a few problems.
At first I could not get the page to scale at all, I figured this out to be a style that sets the max-width to 100% on the svg.
Overriding that style and setting it to
initial
made scaling work as it did on canvas.My second problem is that the performance is really bad when changing the scale, it seems like all child components re-render when i change the scale. I don't think this is necessary? Would it not be possible to just change the scale on the svg element directly without triggering a complete re-render?
Maybe I'm using this wrong and there is a better way to achieve zooming with this library.
If you have any thoughts on this I could possibly help with a PR.
The text was updated successfully, but these errors were encountered: