stephanrauh / ngx-extended-pdf-viewer

A full-blown PDF viewer for Angular 16, 17, and beyond
https://pdfviewer.net
Apache License 2.0
450 stars 167 forks source link

Range request not working #2327

Closed scry-UrjitDesai closed 1 month ago

scry-UrjitDesai commented 1 month ago

Description I want to display a large pdf (>700 pages). I am trying to use range-request for the same. On the showcase, it says that range-request should enabled by default and if my server has range-requests enabled then it should work correctly. The issue I am facing is that even though in my networks tab I can see multiple calls being made to my server and my server returning the appropriate response, the entire pdf is loaded at once only when all the network calls are completed.

To further debug the issue, I tried to set [src] to a path on my local system. Even then, the entire pdf is being loaded all at once only after all the network calls are completed.

Am I missing something? Do you have a working example or some documentation to how I can implement this ?

Here is my angular snippet-

HTML

<ngx-extended-pdf-viewer
    *ngIf="isDocumentLoaded"
    style="position: relative"
    [src]="src"
    #pdfViewer
  ></ngx-extended-pdf-viewer>

TS

ngOnInit(){
this.src = '/assets/1000_pages.pdf';
}

Version info

stephanrauh commented 1 month ago

Good question. It works on my showcase. I suspect sometimes the streaming API interferes with the range requests. The idea of streaming is that the viewer displays pages while loading. That's even better than using range requests. However, I don't know why it refuses to work on some machines. My showcase is a simple Apache httpd server. The configuration activates range requests. I've described it here: https://pdfviewer.net/extended-pdf-viewer/range-requests

If range requests work, it should look like so:

image

In your installation, the chunks should be 64 KB. The showcase configures 128 KB for demonstration purposes.

stephanrauh commented 1 month ago

Did my hint help you? If so, please tell me, so I know I can safely close the ticket.

scry-UrjitDesai commented 1 month ago

Yes, thank you. I have managed to get the range request working on my server. However, I have a use case where in lets assume that i have a list of page numbers. When the user clicks on a page number, I want to load that specific page first and then continue to fetch all the pages using the range-request.

stephanrauh commented 1 month ago

That's pretty much the default behavior of the viewer. Unfortunately, when I implemented the early versions of the viewer, I wasn't able to set the target page number before loading the file. So I've implemented a workaround: the initial page number is 1, and a short time later, [pageNumber] sets the target page number. However, that's after loading the first page.

After loading the document, the viewer works exactly the way you need: it doesn't load unused pages, and loads them only when the user clicks the page. At least, that's how I remember it. If it doesn't work this way, please tell me. Sorry for delegating work to you: I can't check it right now myself because I'm busy at the moment.