# Linearized pdf load incorrectly

**URL:** <https://pdfjs.community/t/linearized-pdf-load-incorrectly/3468>\
**Category:** Technical Support\
**Created:** [October 6, 2024, 1:33pm UTC](https://pdfjs.community/t/linearized-pdf-load-incorrectly/3468 "2024-10-06T13:33:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rvp2k3](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@rvp2k3](https://pdfjs.community/u/rvp2k3)\
**Post date:** [October 6, 2024, 1:33pm UTC](https://pdfjs.community/t/linearized-pdf-load-incorrectly/3468/1 "2024-10-06T13:33:50Z")

</div>

**Which product are you using?**

[PDF.js.Express](http://PDF.js.Express) Plus  
**PDF.js Express Version**  
8.7.4

**Detailed description of issue**  
i tried to load a Linearized pdf file but instead of partial load, webViewer load the whole document. My server has turn on byte range request, and my file is Linearized pdf.)

**Expected behaviour**  
{load file with multiple chunk. }

**Does your issue happen with every document, or just one?**  
{every document}

**Link to document**  
{Provide a link to the document in question if possible}

**Code snippet**  
my web viewer:  
WebViewer(  
{  
path: ‘/public’,  
licenseKey: ‘YOUR\_KEY\_HERE’,  
},  
viewerRef.current  
).then(async (instance) =\> {  
const { docViewer, documentViewer, annotManager, UI, Core } = instance;

```
  docViewer.loadDocument(`url`);

```

}  
my NodeJs server:

fs.stat(pdfPath, (err, stats) =\> {  
if (err) {  
console.error(‘Not Found PDF:’, err);  
return res.sendStatus(404);  
}

```
        const fileSize = stats.size;
        const range = req.headers.range;

        if (range) {
          // ex: Range: bytes=0-1023
          const parts = range.replace(/bytes=/, "").split("-");
          const start = parseInt(parts[0], 10);
          const end = parts[1] ? parseInt(parts[1], 10) : fileSize - 1;

          
          const chunkSize = (end - start) + 1;

        
          const file = fs.createReadStream(pdfPath, { start, end });

          // set headers
          const head = {
            'Content-Range': `bytes ${start}-${end}/${fileSize}`,
            'Accept-Ranges': 'bytes',
            'Content-Length': chunkSize,
            'Content-Type': 'application/pdf',
          };

          res.writeHead(206, head);
          file.pipe(res);
        } else {
          // range not found. sent the whole file
          const head = {
            'Content-Length': fileSize,
            'Content-Type': 'application/pdf',
          };
          res.writeHead(200, head);
          fs.createReadStream(pdfPath).pipe(res);
        }
      });

```

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [October 7, 2024, 9:38pm UTC](https://pdfjs.community/t/linearized-pdf-load-incorrectly/3468/2 "2024-10-07T21:38:36Z")

</div>

Hi there,

Are you able to reproduce this on the demo? [PDF.js Viewer Demo | PDF.js Express](https://pdfjs.express/demo)  
Are you getting the 206 fetch requests in the network panel? Are you getting any console error messages?

Best regards,  
Kevin Kim
