Compare PDF files on iOS

The Apryse SDK provides powerful file comparison functionality. An example of this capability is shown below by comparing two PDF pages and highlighting the difference between them in red.

File 1

File 2

Difference

Apryse Docs Image
Apryse Docs Image
Apryse Docs Image

Show a file comparison view controller

The PTDiffViewController class shows a control to select two documents and create a new file showing the visual difference between them with customizable colors.

Apryse Docs Image

The file comparison control is part of the Tools library, so make sure you have added the Tools library to your project.

1// Initialize a file comparison view controller.
2let diffViewController = PTDiffViewController()
3
4// Set the current view controller as the annotation view controller's delegate.
5diffViewController.delegate = self
6
7let navigationController = UINavigationController(rootViewController: diffViewController)
8if ( UIDevice.current.userInterfaceIdiom == .pad ) {
9 navigationController.modalPresentationStyle = .popover
10 navigationController.popoverPresentationController?.barButtonItem = documentComparisonButton
11}
12
13self.present(navigationController, animated: true, completion: nil)

The diff view controller must be pushed onto a navigation controller's stack before being shown.

Retrieving the file comparison output.

The PTDiffViewController creates an output file showing the visual difference between the two documents in a temporary directory and returns an NSURL with the file's location via a delegate method. To save and display the file, you must conform to the PTDiffViewControllerDelegate protocol.

File comparison sample code

The following sample code demonstrates how to use PDFNet to generate a document displaying the visual difference between two PDF pages:

1func pdfCompareDoc(docA: PTPDFDoc, docB: PTPDFDoc, colorA: PTColorPt, colorB: PTColorPt, blendMode: PTBlendMode) -> PTPDFDoc {
2 let pageA = docA.getPage(1)
3 let pageB = docB.getPage(1)
4
5 let diffOptions:PTDiffOptions = PTDiffOptions()
6 diffOptions.setColorA(colorA)
7 diffOptions.setColorB(colorB)
8 diffOptions.setBlendMode(blendMode)
9
10 let doc:PTPDFDoc = PTPDFDoc()
11 doc.appendVisualDiff(pageA, p2: pageB, opts: diffOptions)
12 return doc
13}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales