PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
CPDFCompareDrawings overlays two documents to produce a new PDF for inspecting drawing revisions. Colors and opacity apply to the overlay result. For structured difference lists, use Content Comparison.
baseDocument and comparedDocument are open. outputPath is a separate output path whose parent directory exists. Run comparison and saving on a background thread.
import android.graphics.Color;
import com.compdfkit.core.compare.CPDFCompareDrawings;
import com.compdfkit.core.document.CPDFDocument;
import com.compdfkit.core.common.CPDFDocumentException;
CPDFCompareDrawings drawings = baseDocument.createCompareDrawings(comparedDocument);
if (drawings != null) {
CPDFDocument generated = null;
try {
drawings.setColorCompare(Color.RED);
drawings.setColorCompared(Color.BLUE);
drawings.setFillAlphaCompare(0.5f);
drawings.setFillAlphaCompared(0.5f);
drawings.setStrokeAlphaCompare(1.0f);
drawings.setStrokeAlphaCompared(1.0f);
drawings.setBlendMode(CPDFCompareDrawings.BlendMode.MULTIPLY);
if (drawings.compareContent()) {
generated = drawings.getDocGenerate(context);
if (generated != null) {
boolean saved = generated.saveAs(outputPath, false);
// Handle the save result.
}
}
} catch (CPDFDocumentException e) {
// Handle output path or save errors.
} finally {
if (generated != null) {
generated.close();
}
drawings.close();
}
}| Method | Description |
|---|---|
setColorCompare(), setColorCompared() | Set colors for the base and compared documents |
setFillAlphaCompare(), setFillAlphaCompared() | Set fill opacity from 0 to 1 |
setStrokeAlphaCompare(), setStrokeAlphaCompared() | Set stroke opacity from 0 to 1 |
setBlendMode() | Set the BlendMode |
compareContent() | Generates the overlay and returns whether it succeeded |
getDocGenerate(context) | Gets the generated document; may return null if generation did not succeed |
The caller owns the generated document and must close it before closing the comparison object. Repeated calls to getDocGenerate() return the same instance.
After retrieving the document, do not call compareContent() again on that comparison object. Create a new object for another comparison. The generated document has no original file path, so save it with saveAs(), not save().