Some test text!

File comparison

Contents

Showing a file comparison view controller
File comparison sample code

The PDFTron 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 1File 2Difference

linkShowing 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.

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

// Initialize a file comparison view controller.
let diffViewController = PTDiffViewController()

// Set the current view controller as the annotation view controller's delegate.
diffViewController.delegate = self

let navigationController = UINavigationController(rootViewController: diffViewController)
if ( UIDevice.current.userInterfaceIdiom == .pad ) {
    navigationController.modalPresentationStyle = .popover
    navigationController.popoverPresentationController?.barButtonItem = documentComparisonButton
}

self.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.

linkFile comparison sample code

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

func pdfCompareDoc(docA: PTPDFDoc, docB: PTPDFDoc, colorA: PTColorPt, colorB: PTColorPt, blendMode: PTBlendMode) -> PTPDFDoc {
    let pageA = docA.getPage(1)
    let pageB = docB.getPage(1)

    let diffOptions:PTDiffOptions = PTDiffOptions()
    diffOptions.setColorA(colorA)
    diffOptions.setColorB(colorB)
    diffOptions.setBlendMode(blendMode)

    let doc:PTPDFDoc = PTPDFDoc()
    doc.appendVisualDiff(pageA, p2: pageB, opts: diffOptions)
    return doc
}

Get the answers you need: Support

Contents

Showing a file comparison view controller
File comparison sample code