Created
November 17, 2013 06:19
-
-
Save ken-muturi/7510006 to your computer and use it in GitHub Desktop.
search & replace text inside pdf files in php applications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $filePath = getcwd() . "\\Input\\MyFile.pdf"; | |
| $fileName = basename($filePath); | |
| $oldText = "old text here"; | |
| $newText = "new text here"; | |
| //set application information | |
| $AppSID = "77**************"; | |
| $AppKey = "89***********"; | |
| //build URI | |
| echo "Uploading pdf file... <br/>"; | |
| $strURIRequest = "http://api.saaspose.com/v1.0" . "/storage/file/" . $fileName; | |
| $signedURI = Sign($strURIRequest); | |
| uploadFileBinary($signedURI, $filePath); | |
| echo "Pdf file has been uploaded successully <br/>"; | |
| echo "Replacing text...<br/>"; | |
| //Build JSON to post | |
| $fieldsArray = array('OldValue'=>$oldText, 'NewValue'=>$newText, 'Regex'=>"false"); | |
| $json = json_encode($fieldsArray); | |
| //Build URI to replace text | |
| $strURI = "http://api.saaspose.com/v1.0" . "/pdf/" . $fileName . "/replaceText"; | |
| $signedURI = Sign($strURI); | |
| $responseStream = processCommand($signedURI, "POST", "json", $json); | |
| $v_output = ValidateOutput($responseStream); | |
| if ($v_output === "") | |
| { | |
| //Save PDF file on server | |
| //build URI | |
| $strURI = "http://api.saaspose.com/v1.0" . "/storage/file/" . $fileName; | |
| //sign URI | |
| $signedURI = Sign($strURI); | |
| $responseStream = processCommand($signedURI, "GET", "", ""); | |
| $outputPath = getcwd() . "\\output\\" . $fileName; | |
| saveFile($responseStream, $outputPath); | |
| echo "The text has been replaced and Pdf file has saved at: " . $outputPath; | |
| } | |
| else | |
| return $v_output; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fatal error: Call to undefined function Sign()