我正在使用csxi来扫描作为图像的文档网络,但我必须将pdf文件上传到服务器。如何在php中将图像转换为PDF?或者有什么方法可以让csxi以PDF格式而不是图像格式扫描文档
发布于 2017-11-17 19:31:32
如果您的机器上安装了ImageMagick,您可以使用ImageMagick bindings for PHP执行一些简单的PHP代码来完成此任务:
$im=new Imagick('my.png');
$im->setImageFormat('pdf');
$im->writeImage('my.pdf');或者,如果你没有可用的ImageMagick,你可以使用像Zamzar这样的商业应用程序接口,它支持通过PHP进行图像到ImageMagick的转换(更多信息,in the docs)。
使用这种方法的代码如下:
<?php
// Build request
$endpoint = "https://api.zamzar.com/v1/jobs";
$apiKey = "YOUR_API_KEY";
$sourceFilePath = "my.png";
$targetFormat = "pdf";
$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);
?>发布于 2012-09-12 17:42:37
将您的图像包装在HTML中并使用诸如fpdf或mpdf之类的HTML to PDF converter
发布于 2014-10-12 01:15:23
对于几张图片,可以使用Chrome web浏览器轻松手动完成。你不需要网络连接。
.html扩展名保存在图像的同一文件夹中:要打开打印dialog
将副本发送到您的smatphone
https://stackoverflow.com/questions/12385325
复制相似问题