使用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.
/**** Section 1 ****/ $appSID = '77****-****-****-****-80*********'; $appKey = '****************'; //build URI to merge PDFs $strURI = 'http://api.aspose.com/v1.1/pdf/MergedFile.pdf/merge'; //sign URI $signedURI = sign($strURI, $appSID, $appKey); /**** End Section 1 ****/ /**** Section 2 ****/ //Build JSON to post $documentsList = array('List'=> array('input1.pdf', 'input2.pdf', 'input3.pdf')); $json = json_encode($documentsList); /**** End Section 2 ****/ /**** Section 3 ****/ $responseStream = processCommand($signedURI, 'PUT', 'json', $json); /**** End Section 3 ****/ /**** Section 4 ****/ //Download merged PDF //build URI $strURI = 'http://stage.aspose.com/v1.1/storage/file/MergedFile.pdf'; //sign URI $signedURI = sign($strURI, $appSID, $appKey); $responseStream = processCommand($signedURI, "GET", "", ""); $outputPath = getcwd() . '/output/MergedFile.pdf'; saveFile($responseStream, $outputPath); echo 'Files have been merged and output file has been saved at: ' . $outputPath; /**** End Section 4 ****/
以上是关于使用PHP REST API合并多个PDF的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 php mpdf 库将多个 PDF 文件合并为一个 PDF
DocuSign Rest API - 需要某些 PDF 字段