使用PHP REST API合并多个PDF

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用PHP REST API合并多个PDF相关的知识,希望对你有一定的参考价值。

php developers can learn how to merge multiple PDF files into a single PDF file using PHP REST API and SDK. To merge PDFs, you need to upload input PDFs to Aspose for Cloud Service or any supported third party storage and then send a PUT request to Aspose for Cloud service.



This REST example uses PHP CURL library to send HTTP request and handle HTTP response so you need to install CURL to use these examples. Once input PDF files are uploaded, you can use the following URI to merge PDFs on Aspose for Cloud or any supported third party storage.



http://api.aspose.com/v1.1/pdf/MergedFile.pdf/merge



You can use a couple of optional parameters with the above mentioned URI. All or specific parameters can be used according to your requirement.



After building URI, you need to go through the following steps:



- Set App SID and App Key and sign URI. See section 1 of the following code and Sign URI method for more details.
- Build JSON to post in the request body. A list of input documents including their paths should be provided. See section 2 of the following code.
- Send a PUT request to Aspose for Cloud service. See section 3 of the following code and processCommand method for more details.
- Download merged PDF file if required. See section 4 of the following code.
  1. /**** Section 1 ****/
  2.  
  3. $appSID = '77****-****-****-****-80*********';
  4. $appKey = '****************';
  5. //build URI to merge PDFs
  6. $strURI = 'http://api.aspose.com/v1.1/pdf/MergedFile.pdf/merge';
  7. //sign URI
  8. $signedURI = sign($strURI, $appSID, $appKey);
  9.  
  10. /**** End Section 1 ****/
  11.  
  12. /**** Section 2 ****/
  13.  
  14. //Build JSON to post
  15. $documentsList = array('List'=> array('input1.pdf', 'input2.pdf', 'input3.pdf'));
  16. $json = json_encode($documentsList);
  17.  
  18. /**** End Section 2 ****/
  19.  
  20. /**** Section 3 ****/
  21. $responseStream = processCommand($signedURI, 'PUT', 'json', $json);
  22.  
  23. /**** End Section 3 ****/
  24.  
  25. /**** Section 4 ****/
  26.  
  27. //Download merged PDF
  28. //build URI
  29. $strURI = 'http://stage.aspose.com/v1.1/storage/file/MergedFile.pdf';
  30. //sign URI
  31. $signedURI = sign($strURI, $appSID, $appKey);
  32. $responseStream = processCommand($signedURI, "GET", "", "");
  33. $outputPath = getcwd() . '/output/MergedFile.pdf';
  34. saveFile($responseStream, $outputPath);
  35. echo 'Files have been merged and output file has been saved at: ' . $outputPath;
  36.  
  37. /**** End Section 4 ****/

以上是关于使用PHP REST API合并多个PDF的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 php mpdf 库将多个 PDF 文件合并为一个 PDF

DocuSign Rest API - 需要某些 PDF 字段

需要将多个 pdf 合并为一个带有目录部分的 PDF

我可以使用现有的SOAP API会话验证Salesforce REST API吗?

M3U8合并最简单的方法

如何在 C# 的 REST API 中获取 PDF 文件