Skip to content

Commit

Permalink
Lazy loading of PDF documents (#37) (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrox authored Oct 18, 2024
1 parent 022ea7d commit f24e611
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,14 @@ const makeTOCItem = item => ({
})

export const makePDF = async file => {
const data = new Uint8Array(await file.arrayBuffer())
const transport = new pdfjsLib.PDFDataRangeTransport(file.size, [])
transport.requestDataRange = (begin, end) => {
file.slice(begin, end).arrayBuffer().then(chunk => {
transport.onDataRange(begin, chunk)
})
}
const pdf = await pdfjsLib.getDocument({
data,
range: transport,
cMapUrl: pdfjsPath('cmaps/'),
standardFontDataUrl: pdfjsPath('standard_fonts/'),
isEvalSupported: false,
Expand Down

0 comments on commit f24e611

Please sign in to comment.