Posted By

johansonkatherine on 05/08/14


Tagged

php input replace pdf text upload a document cloud api in multiple for rest using inside c# cloudReplace texts PDFReplace filereplace creationAsposePdf


Versions (?)

PHP Code Sample to Replace Multiple Text in PDF File Using Cloud API


 / Published in: PHP
 

URL: http://www.aspose.com/docs/display/pdfcloud/Replace+Multiple+Texts+in+a+PDF

The following code sample shows how developers can replace multiple texts in a single API call in a PDF file using Aspose.Pdf for Cloud API in their applications. Developers can use Aspose REST API with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.

  1. use Aspose\Cloud\Common\AsposeApp;
  2. use Aspose\Cloud\Common\Utils;
  3. use Aspose\Cloud\Common\Product;
  4.  
  5. AsposeApp::$appSID = "77******-1***-4***-a***-80**********";
  6. AsposeApp::$appKey = "********************************";
  7.  
  8. $filePath = getcwd() . "/Input/test.pdf";
  9. $fileName = basename($filePath);
  10. $oldText1 = "[!firm!]";
  11. $newText1 = "Aspose";
  12. $oldText2 = "[!client!]";
  13. $newText2 = "Mark";
  14. $oldText3 = "[!transaction_date!]";
  15. $newText3 = "01-01-2014";
  16.  
  17. //build URI
  18. echo "Uploading pdf file... <br/>";
  19. $strURIRequest = "http://api.aspose.com/v1.1/storage/file/" . $fileName;
  20. $signedURI = Utils::sign($strURIRequest);
  21.  
  22. echoUtils::uploadFileBinary($signedURI, $filePath);
  23. echo "Pdf file has been uploaded successully<br/>";
  24.  
  25. echo "Replacing text...<br/>";
  26. //Build JSON to post
  27. $fieldsArray = array('TextReplaces'=>array(array('OldValue'=>$oldText1, 'NewValue'=>$newText1, 'Regex'=>'false'),
  28. array('OldValue'=>$oldText2, 'NewValue'=>$newText2, 'Regex'=>'false'),
  29. array('OldValue'=>$oldText3, 'NewValue'=>$newText3, 'Regex'=>'false')));
  30. $json = json_encode($fieldsArray);
  31.  
  32. //Build URI to replace text
  33. $strURI = "http://api.aspose.com/v1.1/pdf/" . $fileName . "/replaceTextList";
  34. $signedURI = Utils::sign($strURI);
  35.  
  36. $responseStream = Utils::processCommand($signedURI, "POST", "json", $json);
  37.  
  38. //Save PDF file on server
  39. //build URI
  40. $strURI = "http://api.aspose.com/v1.1/storage/file/" . $fileName;
  41. //sign URI
  42. $signedURI = Utils::sign($strURI);
  43. $responseStream = Utils::processCommand($signedURI, "GET", "", "");
  44. $outputPath = getcwd() . "/output/" . $fileName;
  45. Utils::saveFile($responseStream, $outputPath);
  46. echo "The text has been replaced and Pdf file has saved at: " . $outputPath;

Report this snippet  

You need to login to post a comment.