Which product are you using?
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);
}
});