关于PHPPPT类PhpPresentation设置页面大小换算方式

use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\DocumentLayout;
use PhpOffice\PhpPresentation\Style\Border;
use PhpOffice\PhpPresentation\Shape\Drawing;

$objPHPPowerPoint = new PhpPresentation();
//设置界面的宽和高
$oDocumentLayout = new DocumentLayout();
$oDocumentLayout->setDocumentLayout(array('cx' => 12192000, 'cy' => 6858000), true);#这里的cx宽高cy可以通过px乘以9525得到或通过厘米乘以360000得到
$objPHPPowerPoint->setLayout($oDocumentLayout);
$objPHPPowerPoint->removeSlideByIndex(0);

来自PhpPresentation库注释换算说明

 * 1 px = 9525 EMU @ 96dpi (which is seems to be the default)

     * Absolute distances are specified in English Metric Units (EMUs),

     * occasionally referred to as A units; there are 360000 EMUs per

     * centimeter, 914400 EMUs per inch, 12700 EMUs per point.

foreach ($content as $k=>$vimg){
            if($imginfo=getimagesize($vimg)){
                $width=$imginfo[0];
                $height=$imginfo[1];
                if($width>860){
                    $imgwh=getImgewh($vimg,860);
                    $width=$imgwh['width'];
                    $height=$imgwh['height'];
                }
                if($height>470){
                    $imgwh=getImgewh($vimg,'',470);
                    $width=$imgwh['width'];
                    $height=$imgwh['height'];
                }
                $shape = $slide->createDrawingShape();
                $shape->setName('内容图片');
                $shape->setDescription('内容图片');
                //只有本地路径才能正常读取
                $shape->setPath($vimg);
                $shape->setHeight($height);
                $shape->setWidth($width);
                $shape->setOffsetX(86+$k*50);//定位位置厘米*37.5
                $shape->setOffsetY(265);
            }
        }


支付宝扫码打赏 微信扫码打赏

如果本文对你有帮助,欢迎打赏本站

喜欢 ()or分享
    匿名评论
  • 评论
人参与,条评论