Lazy loading of PDF documents (#37) (#38)

This commit is contained in:
Huang Xin
2024-10-18 04:05:31 +00:00
committed by GitHub
parent 022ea7da87
commit f24e611c4e
+7 -2
View File
@@ -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,