最近比较火的文档转换工具相信大家都听说过,但是怎么实现呢? 通过该接口可以将图片、Word、excel、ppt等文档转换为pdf格式的文件 可以将Office(Word,Excel,PowerPoint)文件转换为PDF。 转换文件内容、格
最近比较火的文档转换工具相信大家都听说过,但是怎么实现呢?
通过该接口可以将图片、Word、excel、ppt等文档转换为pdf格式的文件
可以将Office(Word,Excel,PowerPoint)文件转换为PDF。
转换文件内容、格式、页数等和原文件一致。
实现代码如下:
开发工具 的参数填写,或者直接复制开发工具下面的测试代码。 'key' => $API_KEY,'fileurl' => 'https://www.xxxx.com/文档转换工具.pdf',);//签名校验的 SK:(在用户控制台密钥管理的秘钥安全设置->签名校验 开启后才会生效,没开启签名校验留空即可。)$sk = '1a78feda123123213213217f1ba3466ef';$resdata = api::send($API_URL, $get_post_data, '选方法', true, $sk); //发起请求,注意这里要选择接口支持的协议,默认GET,可选POST//打印请求结果print($resdata);///你的业务代码可写在这里处理API返回的数据class api{ public static function send($API_URL, $get_post_data, $type, $ifsign, $sk) { $get_post_data = Http_build_query($get_post_data); if ($ifsign) { $sign = md5($get_post_data . $sk); $res = self::send_curl($API_URL, $type, $get_post_data, $sign); } else { $res = self::send_curl($API_URL, $type, $get_post_data, null); } return $res; } //封装好的CURL请求函数,支持POST|GET public static function send_curl($API_URL, $type, $get_post_data, $sign) { $ch = curl_init(); if ($type == 'POST') { curl_setopt($ch, CURLOPT_URL, $API_URL); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $get_post_data); } elseif ($type == 'GET') { curl_setopt($ch, CURLOPT_URL, $API_URL . '?' . $get_post_data); } if ($sign) { curl_setopt($ch, CURLOPT_HTTPHEADER, ['sign:' . $sign]); } curl_setopt($ch, CURLOPT_REFERER, $API_URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $resdata = curl_exec($ch); curl_close($ch); return $resdata; }}
提交成功后需查询成功状态,需要定时去轮训,我们建议最低5秒一次。
来源地址:https://blog.csdn.net/shunweiservice/article/details/127101875
--结束END--
本文标题: Word转PDF功能实现,文档转换工具通过PHP开发
本文链接: https://www.lsjlt.com/news/390193.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0