fix(pdf): pdf quality and multiline #204
@ -94,11 +94,14 @@ export const pdfToImages = async (
|
|||||||
const pages: PdfPage[] = []
|
const pages: PdfPage[] = []
|
||||||
const pdf = await PDFJS.getDocument(data).promise
|
const pdf = await PDFJS.getDocument(data).promise
|
||||||
const canvas = document.createElement('canvas')
|
const canvas = document.createElement('canvas')
|
||||||
|
const width = getInnerContentWidth()
|
||||||
|
|
||||||
for (let i = 0; i < pdf.numPages; i++) {
|
for (let i = 0; i < pdf.numPages; i++) {
|
||||||
const page = await pdf.getPage(i + 1)
|
const page = await pdf.getPage(i + 1)
|
||||||
|
|
||||||
const viewport = page.getViewport({ scale: 1 })
|
const originalViewport = page.getViewport({ scale: 1 })
|
||||||
|
const scale = width / originalViewport.width
|
||||||
|
const viewport = page.getViewport({ scale: scale })
|
||||||
const context = canvas.getContext('2d')
|
const context = canvas.getContext('2d')
|
||||||
canvas.height = viewport.height
|
canvas.height = viewport.height
|
||||||
canvas.width = viewport.width
|
canvas.width = viewport.width
|
||||||
@ -106,7 +109,7 @@ export const pdfToImages = async (
|
|||||||
await page.render({ canvasContext: context!, viewport: viewport }).promise
|
await page.render({ canvasContext: context!, viewport: viewport }).promise
|
||||||
pages.push({
|
pages.push({
|
||||||
image: canvas.toDataURL(),
|
image: canvas.toDataURL(),
|
||||||
width: viewport.width,
|
width: originalViewport.width,
|
||||||
drawnFields: []
|
drawnFields: []
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user