|
@@ -213,9 +213,9 @@
|
|
|
<el-dropdown-item command="word">Word格式</el-dropdown-item
|
|
|
><!-- word -->
|
|
|
<el-dropdown-item command="pdf">PDF格式</el-dropdown-item>
|
|
|
- <el-dropdown-item command="pdf-to-word"
|
|
|
- >PDF转Word</el-dropdown-item
|
|
|
- >
|
|
|
+ <!-- <el-dropdown-item command="pdf-to-word"
|
|
|
+ >Word</el-dropdown-item
|
|
|
+ > -->
|
|
|
</el-dropdown-menu>
|
|
|
</template>
|
|
|
</el-dropdown>
|
|
@@ -510,7 +510,7 @@ export default {
|
|
|
</style>
|
|
|
</head>
|
|
|
<body>
|
|
|
- ${contentContainer.innerHTML}
|
|
|
+ ${this.processImages(contentContainer.innerHTML)}
|
|
|
</body>
|
|
|
</html>`;
|
|
|
|
|
@@ -1838,7 +1838,7 @@ export default {
|
|
|
this.$alert(res.errMsg);
|
|
|
return;
|
|
|
}
|
|
|
- console.log(res)
|
|
|
+ console.log(res);
|
|
|
// 处理文件下载
|
|
|
const link = document.createElement("a");
|
|
|
link.href = res.data.data.file_path;
|
|
@@ -1968,40 +1968,51 @@ export default {
|
|
|
processImages(content) {
|
|
|
const tempDiv = document.createElement("div");
|
|
|
tempDiv.innerHTML = content;
|
|
|
-
|
|
|
// 处理所有图片
|
|
|
tempDiv.querySelectorAll("img").forEach((img) => {
|
|
|
- // 保存原始宽高属性
|
|
|
- const originalWidth = img.getAttribute("width");
|
|
|
- const originalHeight = img.getAttribute("height");
|
|
|
-
|
|
|
// 创建图片容器
|
|
|
const container = document.createElement("div");
|
|
|
container.className = "image-container";
|
|
|
-
|
|
|
- // 设置图片样式
|
|
|
- img.style.maxWidth = "100%";
|
|
|
- img.style.height = "auto";
|
|
|
-
|
|
|
- // 如果有原始尺寸,使用原始尺寸(但确保不超过页面宽度)
|
|
|
- if (originalWidth && originalHeight) {
|
|
|
- const aspectRatio = originalWidth / originalHeight;
|
|
|
- const maxWidth = 595; // A4纸宽度(像素,减去边距)
|
|
|
-
|
|
|
- if (originalWidth > maxWidth) {
|
|
|
- img.style.width = maxWidth + "px";
|
|
|
- img.style.height = maxWidth / aspectRatio + "px";
|
|
|
- } else {
|
|
|
- img.style.width = originalWidth + "px";
|
|
|
- img.style.height = originalHeight + "px";
|
|
|
- }
|
|
|
+ // 获取所有可能的尺寸来源
|
|
|
+ let width =
|
|
|
+ img.getAttribute("width") || img.style.width || img.width || null;
|
|
|
+ let height =
|
|
|
+ img.getAttribute("height") || img.style.height || img.height || null;
|
|
|
+ // 移除单位并转换为数字
|
|
|
+ if (typeof width === "string") {
|
|
|
+ width = parseInt(width.replace(/[^0-9]/g, ""));
|
|
|
}
|
|
|
-
|
|
|
+ if (typeof height === "string") {
|
|
|
+ height = parseInt(height.replace(/[^0-9]/g, ""));
|
|
|
+ }
|
|
|
+ // 如果没有尺寸,创建一个临时图片来获取实际尺寸
|
|
|
+ if (!width || !height) {
|
|
|
+ const tempImg = new Image();
|
|
|
+ tempImg.src = img.src;
|
|
|
+ width = tempImg.width || 595; // 默认宽度
|
|
|
+ height = tempImg.height || Math.round(width * 0.75); // 默认高度比例
|
|
|
+ }
|
|
|
+ // 确保数值有效
|
|
|
+ width = Math.max(1, parseInt(width));
|
|
|
+ height = Math.max(1, parseInt(height));
|
|
|
+ // 处理尺寸
|
|
|
+ const maxWidth = 595; // A4纸宽度(像素,减去边距)
|
|
|
+ if (width > maxWidth) {
|
|
|
+ // 等比例缩放
|
|
|
+ const aspectRatio = width / height;
|
|
|
+ const newHeight = Math.round(maxWidth / aspectRatio);
|
|
|
+ width = maxWidth;
|
|
|
+ height = newHeight;
|
|
|
+ }
|
|
|
+ // 同时设置style和属性
|
|
|
+ img.style.width = `${width}px`;
|
|
|
+ img.style.height = `${height}px`;
|
|
|
+ img.setAttribute("width", width);
|
|
|
+ img.setAttribute("height", height);
|
|
|
// 将图片包装在容器中
|
|
|
img.parentNode.insertBefore(container, img);
|
|
|
container.appendChild(img);
|
|
|
});
|
|
|
-
|
|
|
return tempDiv.innerHTML;
|
|
|
},
|
|
|
},
|