【问题标题】:How to use ConvertAPI Word2Pdf?如何使用 ConvertAPI Word2Pdf?
【发布时间】:2014-07-01 13:07:49
【问题描述】:

我正在尝试调用 ConvertAPI.com/Word2Pdf,但没有成功。

我的示例代码是:

$fileToConvert = 'test.docx';
$apiKey = *******;
$postdata = array('OutputFileName' => 'test.pdf', 'ApiKey' => $apiKey, 'File' => $fileToConvert);
$ch = curl_init("http://do.convertapi.com/Word2Pdf");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$result = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
var_dump($result);

我得到的结果类似于:“HTTP/1.1 100 Continue HTTP/1.1 400 'File' 参数不能为空。请设置值。缓存控制:无缓存,无存储杂注:无-cache Content-Type: text/html..."

我在这里做错了什么?

【问题讨论】:

  • test.docx 文件是否存在?也许尝试使用该文件的绝对路径?
  • 是的。它存在,并且与此 php 文件位于同一文件夹中...
  • 我尝试过使用绝对路径,但得到了相同的结果...
  • 自从我的主机从 php 5.4 升级到 php 5.6 我得到了同样的错误。你找到任何解决方案了吗? (不是最统一的方式)。我已经向他们的支持部门发送了多封电子邮件,但根本没有任何回应......
  • @COBIZwebdevelopment 正如我在已接受答案的评论中所写,我没有使用 unirest,解决方案是将 @ 添加到文件名: $postdata = array('OutputFileName' = > 'test.pdf', 'ApiKey' => $apiKey, 'File' => "@" . $fileToConvert);

标签: php convertapi


【解决方案1】:

使用http://unirest.io/php.html 库试试这个

$response = Unirest::post(
  "http://do.convertapi.com/Word2Pdf?ApiKey=<Your api key>",
  array(
    "File" => "@/tmp/file.path",
    "OutputFormat" => "pdf",
  )
);

【讨论】:

  • 我在几分钟前以类似的方式解决了它。关键是文件名的@前缀。
  • 我正在尝试这个解决方案,但没有任何效果,有什么建议吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-27
  • 2019-11-02
  • 1970-01-01
  • 2014-12-16
  • 1970-01-01
  • 2019-05-10
  • 1970-01-01
相关资源
最近更新 更多