From 0d2fe7655fd120ade30513edef359f6a87f4c1b2 Mon Sep 17 00:00:00 2001 From: zhangxuelin <959231531@qq.com> Date: Fri, 26 Jul 2024 15:32:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AEpdf=20=E6=AF=94=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/components/pdf/index.vue | 41 +++++++++++------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/renderer/src/components/pdf/index.vue b/src/renderer/src/components/pdf/index.vue index 3ac1cf6..75a64d6 100644 --- a/src/renderer/src/components/pdf/index.vue +++ b/src/renderer/src/components/pdf/index.vue @@ -50,8 +50,7 @@ const renderPage = async (canvasobj) => { const pdf = await pdfjsLib.getDocument(props.pdfObj.pdfUrl).promise // 渲染当前页 const page = await pdf.getPage(canvasobj.page) - const viewport = page.getViewport({ scale: 1 }) - + const viewport = page.getViewport({ scale: 1.28 }) const canvasElement = canvasobj.canvas canvasElement.width = viewport.width canvasElement.height = viewport.height @@ -67,34 +66,34 @@ const renderPage = async (canvasobj) => { img.onload = () => { // 在这里执行图像加载完成后的操作 // 根据传过来的pdf对象 判断改渲染哪一个fabric - var screenWidth = window.innerWidth/2-10; - var screenHeight = window.innerHeight; - // 计算图像的原始宽度和高度 - var imgWidth = img.width; - var imgHeight = img.height; - // 计算图像的缩放比例以适应屏幕 - var widthRatio = screenWidth / imgWidth; - var heightRatio = screenHeight / imgHeight; - //选择较小的缩放比例以确保图像完全适应屏幕 - var scaleRatio = Math.min(widthRatio, heightRatio); - // 计算缩放后的图像尺寸 - var targetWidth = imgWidth * scaleRatio; - var targetHeight = imgHeight * scaleRatio; + // var screenWidth = window.innerWidth/2-10; + // var screenHeight = window.innerHeight; + // // 计算图像的原始宽度和高度 + // var imgWidth = img.width; + // var imgHeight = img.height; + // // 计算图像的缩放比例以适应屏幕 + // var widthRatio = screenWidth / imgWidth; + // var heightRatio = screenHeight / imgHeight; + // //选择较小的缩放比例以确保图像完全适应屏幕 + // var scaleRatio = Math.min(widthRatio, heightRatio); + // // 计算缩放后的图像尺寸 + // var targetWidth = imgWidth * scaleRatio; + // var targetHeight = imgHeight * scaleRatio; if (props.pdfObj.numberOfPdf == 2) { if (canvasobj.index == 0) { - fabriccanvas.value.setWidth(targetWidth) - fabriccanvas.value.setHeight(targetHeight) + fabriccanvas.value.setWidth(img.width) + fabriccanvas.value.setHeight(img.height) displayData(fabriccanvas, canvsStore, canvasobj, fabric, img) } else { - fabriccanvas1.value.setWidth(targetWidth) - fabriccanvas1.value.setHeight(targetHeight) + fabriccanvas1.value.setWidth(img.width) + fabriccanvas1.value.setHeight(img.height) displayData(fabriccanvas1, canvsStore, canvasobj, fabric, img) } } else { - fabriccanvas.value.setWidth(targetWidth) - fabriccanvas.value.setHeight(targetHeight) + fabriccanvas.value.setWidth(img.width) + fabriccanvas.value.setHeight(img.height) displayData(fabriccanvas, canvsStore, canvasobj, fabric, img) } // console.log(imgarr.value)