-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Adding PageViewport to exports #11239
Conversation
Why do you need to manually initialize a Lines 956 to 973 in 16ae7c6
Most likely, you'll need to provide a good explanation/example of why this change is necessary in order for the PR to be considered. |
The point is: I'm not trying to "obtain" a viewport, I'm trying to create a new one. What's the purpose? - You might ask. I work on a project where it's essential to get only a portion of a pdf rendered. I determine that portion with a newly created PageViewport. Any other questions/suggestions are welcome. |
So you're not calling pdf.js/src/display/display_utils.js Lines 252 to 267 in 16ae7c6
|
To me that sounds like a workaround, rather than a solution. Also, getters usually don't need parameters, neither "clone" functions. With all due respect, these are kind of counterintuitive to me. If you had a "Circle" class, and I need to create a "new Circle", I'd rather not do it like this: |
I'm slightly confused here, since there shouldn't be any getters involved here... My general point though is that you want to avoid extending the API surface, especially with code which is completely unused/untested in the general library, if the relevant functionality is already being exposed elsewhere. |
Maybe it's my poor choice of words, by I doubt it's unused/untested, because before my current approach (using |
The global
The code in #11239 (comment) creates a new Given /~https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L867 and your specific use-case I'm not against adding it to the exports. However, alternatively we could consider updating |
In theory it should work, but as I mentioned, it looks hacky (I'm not sure if my "Circle" metaphor above makes any sense to you). BTW I tried with that method, and it doesn't work for me, gives me a blank (white) image, so in practice, it doesn't work. Is it possible that Anyway, I don't see any reason why we shouldn't expose this class. It was public in the recent past, some of us need it, so why not expose it again? |
Any news on this? |
It would be most helpful if you could provide a link to your code (or a reduced test-case), such that it's possible to see how this is actually being used, since it's quite difficult to understand the exact requirements otherwise and the discussion thus becomes a bit theoretical.
I don't believe that
My point was that the change proposed in this PR adds code which is unused/untested (from the perspective of the library), and thus cannot be guaranteed to remain available. |
@Snuffleupagus thanks, I'll prepare a demo in the following days of my use-case. Is there any jsfiddle template available with this lib? |
Possibly the "Edit in JSFiddle" links found at https://mozilla.github.io/pdf.js/examples/#interactive-examples could be used as a starting point. |
@Snuffleupagus So instead of that, I'm going to link my old demo, which uses the old library (where this class was still available): http://vargapeter.info/works/pdf-rasterizer/ The point of this is that it splits the PDF into multiple canvases (like a tile-system), so they can be used as webgl textures. The relevant part is at So basically what I need is the ability to pass a custom viewport (with offset, rotation, scale, etc) to the renderContext, before rasterizing the pdf. Exposing the pageviewport class makes this super easy, while not-exposing it makes it impossible (as far as I know). |
Looking very briefly at the code, it appears that Lines 948 to 954 in d7f651a
Assuming that's actually correct, then it looks like what you really need here is the ability to pass custom offsets to PDFPageProxy.getViewport and/or PageViewport.clone which shouldn't be difficult to support (in a way that's tested and thus more future-proof).
|
@Snuffleupagus |
Please see PR #11273.
Sorry, but I'm not sure that I really understand how using an existing, well-established, documented, and unit-tested API method, i.e. The point is that by simply extending a pre-existing API method to accept new options, it's easy to ensure that the functionality remains available and, thanks to the unit-tests, working even with any future code changes. (There's no guarantees of either with the approach suggest in this PR, unfortunately.) Generally speaking: Please note that the more functionality you're exposing as part of the public API, the more difficult maintaining the code becomes. Basically, as soon as something is exposed publicly then fixing bugs, adding features, and/or re-factoring code all has the potential to be difficult (which experience has shown). Hence the reason for not wanting to unnecessarily export things unless absolutely necessary. |
@Snuffleupagus What I meant by "difficult" is that the exposing can be done in 1 single line (what this PR does), whereas the other solution surely needs more work. What I meant by "less elegant" is the way it's going to be used. IMHO I don't know much about the inner parts of this lib (unit tests / whatever), so if you're saying that you're proposed PR is safer / better / etc, I'm going to believe you, no questions asked. Again: As long as it works, I'm fine with it, and thank you for your time and effort for making this possible. So, as far as I understand, if someone wants to have a custom pageviewport, instead of this:
They need to use it like this:
Is that right? |
Yes. Thanks to the pull request above, you can then pass |
Right now I use a very dirty hack to be able to create an instance of a PageViewport, this PR solves this issue.