mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Convert PDF.js code to TypeScript
GitOrigin-RevId: 840bc48816d78497131b927522b4f6f7940bb0c4
This commit is contained in:
+5
-9
@@ -140,14 +140,16 @@ export class GraphicsWidget extends WidgetType {
|
||||
}
|
||||
|
||||
async renderPDF(view: EditorView, canvas: HTMLCanvasElement, url: string) {
|
||||
const { PDFJS } = await this.importPDFJS()
|
||||
const { loadPdfDocumentFromUrl } = await import(
|
||||
'@/features/pdf-preview/util/pdf-js'
|
||||
)
|
||||
|
||||
// bail out if loading PDF.js took too long
|
||||
if (this.destroyed) {
|
||||
return
|
||||
}
|
||||
|
||||
const pdf = await PDFJS.getDocument({ url, isEvalSupported: false }).promise
|
||||
const pdf = await loadPdfDocumentFromUrl(url).promise
|
||||
const page = await pdf.getPage(1)
|
||||
|
||||
// bail out if loading the PDF took too long
|
||||
@@ -162,16 +164,10 @@ export class GraphicsWidget extends WidgetType {
|
||||
canvas.style.width = width
|
||||
canvas.style.maxWidth = width
|
||||
page.render({
|
||||
canvasContext: canvas.getContext('2d'),
|
||||
canvasContext: canvas.getContext('2d')!,
|
||||
viewport,
|
||||
})
|
||||
this.height = viewport.height
|
||||
view.requestMeasure()
|
||||
}
|
||||
|
||||
async importPDFJS(): Promise<any> {
|
||||
return import('../../../../pdf-preview/util/pdf-js-versions').then(
|
||||
m => m.default
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user