首页 > 解决方案 > 使用 pptxgenjs,添加一张完整的幻灯片图片

问题描述

PptxGenJS 允许通过脚本创建 Powerpoint 文件。 https://gitbrent.github.io/PptxGenJS/

我们可以按如下方式添加图像:

slide.addImage({ path: "images/chart_world_peace_near.png", x:..., y:..., w:..., h:...});

我需要使用纵横比将图像调整为幻灯片的全尺寸。所以,我需要知道图片的大小和幻灯片的大小,如下:

scaled_image_width = slide_width
scaled_image_height = image_height * scaled_image_width / image_width;
if (scaled_image_height > slide_height) {
  scaled_image_height = slide_height
  scaled_image_width = image_width * scaled_image_height / image_height;
}

但是,我在 PptxGenJS 中看不到获取图像大小和幻灯片大小的方法。我怎样才能做到这一点?

标签: pptxgenjs

解决方案


您可以使用下面为幻灯片添加背景

var pptx1 = new PptxGenJS();
var slide = pptx1.addSlide();

添加幻灯片后,您可以为其添加背景

slide.background = {path:"Image URL"};

推荐阅读