文库网站的文件转换源码分享

154 阅读1分钟

文库网站获利的方式就在于文库网站巨大的广告能力,还有会员充值下载。文库是在线分享的平台。

文件的格式有很多

doc(.docx)、.ppt(.pptx)、.xls(.xlsx)、.pot、.pps、.vsd、.rtf、.wps、.et、.dps、.pdf、.txt(可v+wxyetu)。那么文库网站的转换功能就很重要。

image.png

image.png

image.png

image.png 下面分享一下文库PPT转换成JPG图片的源码,这是文库获利的重要一步

$file='E:/APP/OTHER/qwe.pptx';  
$presentation = $powerpnt->Presentations->Open(realpath($file), false, false, false) or die("Unable to open presentation");  
foreach($presentation->Slides as $slide)  
{  
$slideName = "Slide_" . $slide->SlideNumber;  
$uploadsFolder = 'iii';  
$exportFolder = realpath($uploadsFolder);  
$slide->Export($exportFolder."//".$slideName.".jpg", "jpg", "600", "400");  
}  
$presentation->Close();  
$powerpnt->Quit();  
$powerpnt = null;  
  
?>

内容扩展

从shell脚本中,您可以使用Unoconv,它是LibreOffice的简单命令行包装器,可以使您转换为合理的质量。

对于可以直接从PHP(以及Linux)调用的具有更高质量输出的解决方案,您可以使用专用文件转换API,例如Zamzar。

提交PPT(或PPTX)文件以转换为JPEG的代码如下

$endpoint = "https://api.zamzar.com/v1/jobs";  
$apiKey = "YOUR_KEY";  
$sourceFilePath = "/tmp/my.ppt"; // Or PPTX  
$targetFormat = "jpg";  
$sourceFile = curl_file_create($sourceFilePath);  
$postData = array(  
"source_file" => $sourceFile,  
"target_format" => $targetFormat  
);  
// Send request  
$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL, $endpoint);  
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');  
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);  
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
curl_setopt($ch, CURLOPT_USERPWD, $apiKey . ":");  
$body = curl_exec($ch);  
curl_close($ch);  
// Process response (with link to converted files)  
$response = json_decode($body, true);  
print_r($response);  
?>