Posted By

johansonkatherine on 03/13/14


Tagged

php file merge pdf new files into cloud api in multiple for rest using one PDFs PHPMerge cloudMerging APIMerge RESTMerge SDKcreating PDFREST merging


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

mmbalaa


Merge multiple PDFs using PHP REST API


 / Published in: Java
 

URL: http://www.aspose.com/blogs/aspose-products/aspose-pdf-product-family/archive/2014/03/06/merge-multiple-pdf-files-into-one-pdf-in-php.html

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 ****/

Report this snippet  

You need to login to post a comment.