Closed NourKhashan closed 1 month ago
Good question... but I'm pretty sure these two settings are bad for you:
pdfDefaultOptions.disableAutoFetch=true;
pdfDefaultOptions.disableStream =true;
Just stick to the defaults. I also suspect your rangeChunkSize
is too big. The default is 64 KB, and it works in my showcase without any configuration.
I assume the second code snippet is C# code?
Yes it's c#
I tried to Comment rangeChunkSize and tried also to set it to 64 KB but still the same. Range Doesn't Send I comment disableAutoFetch and disableStream
// pdfDefaultOptions.rangeChunkSize=1024*64;
pdfDefaultOptions.disableRange=false;
// pdfDefaultOptions.disableAutoFetch=true;
// pdfDefaultOptions.disableStream =true;
The reponse header is more important than the request. The first response should look like this:
I've described the details here: https://pdfviewer.net/extended-pdf-viewer/range-requests
Yes I already followed this Link and this is my response In first request the range is null -this is my problem range doesnt send- so according to link we return the whole file but it suppose for first call to not return the whole File it should return first chunk of file to enhancement Performance. I tried to not to return the whole file it gives me 500 Server Error. After this In second request in the request header range send Which is incorrect. it doesnt even get first chunk.
Ah, we're getting closer. To be honest, this is a part of the viewer I haven't fully understood.
If my research is correct, the first request is a traditional request without range requests. You know, in the beginning, the PDF viewer doesn't know whether the server supports range requests or not. When the PDF viewer detects that the server is able to process range requests, it cancels the first request and starts sending range requests.
It's the server's responsibility to stop sending data when the client has canceled the request. I don't know how you've implemented your server. I suspect you must care about canceling the request explicitly.
@Timvandermeij I know my idea doesn't make much sense for the Firefox PDF viewer - but still, I wonder if I should add a mode that starts requesting range requests immediately. Maybe I'm wrong, but to me, the current approach of fetching the entire file and canceling the request doesn't feel efficient.
What's your opinion? And is there a documentation explaining how pdf.js implements streaming and range requests?
I tried to cancel request and try to send StatusCode CancelRequest Or even tried to created empty bytes with same length but i gives me 500 So Do u mean it's normal that Range in First Request to be null and return whole File as this is get request?
I have others Question if u dont mind
As I showed to u in Second Request it start to get last chucks first does it also normal? As I expexted to get First Chucks First
Why u Recommend to not change disableAutoFetch and disableStream
Is there a way to determined how many chunks to load first -or set no. of Pages To Load First and send request based on it I know for each page has different size -and when I scroll Load the related chunks as I see there is a lot of partial request to get whole file and this a lot of requests?
I tried to change pdfDefaultOptions.rangeChunkSize I dont want default value -64KB- but it doesnt reflect. I set it in ctor. Do I have to change it in another place?
@timvandermeij I know my idea doesn't make much sense for the Firefox PDF viewer - but still, I wonder if I should add a mode that starts requesting range requests immediately. Maybe I'm wrong, but to me, the current approach of fetching the entire file and canceling the request doesn't feel efficient.
What's your opinion? And is there a documentation explaining how pdf.js implements streaming and range requests?
Documentation, and my knowledge, about this is a bit sparse unfortunately, but I think https://github.com/mozilla/pdf.js/issues/11669#issuecomment-596586198 explains the situation well and should still be correct. There is also d0297cfb97c14385/src/display/api.js#L197-L206, https://github.com/mozilla/pdf.js/pull/8768 and https://github.com/mozilla/pdf.js/issues/6126 that might help. If you would like to know more, you can also ask in the PDF.js Matrix room; please see https://github.com/mozilla/pdf.js?tab=readme-ov-file#questions.
Ah Thanks, I also can't find plenty and suitable resources. But I will continue digging in this. So thanks again I appreciate ur time.
@NourKhashan You can debug what's going on in the client side. Just set the attribute [minifiedJSLibraries]="false"
and locate the code dealing with range requests. I'm not entirely sure, but I think it's somewhere in this class: https://github.com/stephanrauh/pdf.js/blob/3b6b63aad3e986e49731c08bc314c543f6c13565/src/core/worker.js#L266
Oh, and I'm 99% sure the issue is on the server side. On the client side, range requests work out-of-the-box if the server supports them.
Whether tweaking the size of the chunks is a good idea or not probably depends on the size of the PDF pages. For most documents, 64K is a good choice.
In Server Side I do as documentation and in documentation in Get Request it return whole File if Range Request Is Null, Range is send as null from Client Side and this is point and it take alot of time. After this request range is send but not for beginning - but this is a proof that server support range- . If this Related to Server Side Does it related to Response Headers As I showd to u Request and Response Header For First Request.
I'm closing this ticket now because I think I've told you everything I know about the topic and because I don't support old version of ngx-extended-pdf-viewer. I'd like to support old versions, but it's simply not possible because I don't have enough time to spare, so I reluctantly focus on the current version.
I need your help! I have Large File (1 GB), So I dont want to download whole file as I take alot of time to display fist page. So I want to use rangeChunkSize to get 1 MB Bytes of file and when scrolling I want to get next 1 MB but it doesnt work the range header doesnt send, therefore whole file download.
Check this first this is my Setting
In Get Method In API I Set Response Header
Describe the bug But in Request the range header doesnt sent with URL, and I use .net Core it support Range Header. Do I need in backend to add another api with specific header before get request or what missconfigure that i do.
Version info ngx-extended-pdf-viewe : 12.1.2 Angular CLI: 12.1.1 Node: 14.15.0
Thanks In Advance