Compare two PDF using PHP

Highly accurate PHP diff checker to compare PDF files and find differences between them

Our powerful PHP SDK allows you to find the difference between PDF documents and save the results to a convenient format for viewing. To verify our product capabilities, compare PDF files using this PHP library and see the differences.

View code snippet

Compare PDF in PHP

Our PHP SDK is designed to give you the most accurate result, even though comparison is a complex function itself.

Sometimes you need to be sure that the document in the PDF format has not been changed, and if it has, you need to find out what the difference is. Just use our PHP diff tool to compare two PDF files and find differences in whole words or single characters. Moreover, if only one character in a word has changed, this word will be marked as changed entirely.

Now you no longer need to spend time manually comparing PDF documents, and you can quickly find even small changes and export such diffs to a document in a convenient format.

Try to compare PDF documents

Check out how our solution to compare PDF files using PHP SDK works. To achieve this, load the PDF files you want to compare and select the export file format – it will be automatically loaded after comparing.

Note that you need to accept all revisions in compared documents before calling the comparison method, as shown in our example:

Upload the compared file
Run code
Upload the second file to compare
Select the target format from the list
use Aspose\Words\WordsApi;

$wordsApi = new WordsApi('####-####-####-####-####', '##################');
$fileName1 = "Input1.pdf";
$fileName2 = "Input2.pdf";
$fileResult = "Output.pdf";

/**
 *  Upload documents to cloud storage.
 */
$firstDocumentContent = $fileName1;
$uploadFirstFileRequest = new UploadFileRequest(
    $firstDocumentContent, $fileName1, NULL
);
$wordsApi->uploadFile($uploadFirstFileRequest);

$secondDocumentContent = $fileName2;
$uploadSecondFileRequest = new UploadFileRequest(
    $secondDocumentContent, $fileName2, NULL
);
$wordsApi->uploadFile($uploadSecondFileRequest);

/**
 *  Compare documents in cloud.
 */
$compareDataOptions = new CompareData(array(
    "author" => "author",
    "file_reference" => FileReference::fromRemoteFilePath($fileName2)
));
$compareDocumentRequest = new CompareDocumentRequest(
    $fileName1, $compareDataOptions, NULL, NULL, NULL, NULL, NULL, $fileResult, NULL
);
$wordsApi->compareDocument($compareDocumentRequest);

/**
 *  Download result document from cloud storage.
 */
$downloadFileRequest = new DownloadFileRequest(
    $fileResult, NULL, NULL
);
$downloadFileResult = $wordsApi->downloadFile($downloadFileRequest);
rename(reset($downloadFileResult)->getPathname(), 'compareResult.pdf');
Run code
  
Copy PHP code to the clipboard

How to Compare two text files

  1. Install Aspose.Words Cloud for PHP
  2. Add a library reference (import the library) to your PHP project
  3. Load two PDF documents to compare
  4. Call the compareDocument() method to compare PDF docs
  5. Download the result document from the cloud storage

PHP library to use compare

Install 'Aspose.Words Cloud SDK for PHP' from Packagist repository. Just run composer require aspose-cloud/aspose-words-cloud to install the SDK, then use require_once('vendor/autoload.php'); to import it into your project.

As an alternative, you can manually clone Aspose.Words Cloud SDK for PHP source code from GitHub. Please follow these Instructions to quickly get the necessary security credentials and access our REST API.

System Requirements

PHP 7.1 or newer

Refer to the Repository Documentation to see more details.

Other supported file formats

You can perform compare operation for other file formats:

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2024. All Rights Reserved.