On this page
Compress & Optimize a PDF File
Control the compression accuracy of images and observe the compression progress in real-time by setting the CPDFDocumentOptimizeOption
parameter.
Below is an example code for configuring the compression and optimization of PDF files:
java
CPDFDocument document = new CPDFDocument(context);
document.open("xxx.pdf");
// Compress & Optimize a PDF File
try {
boolean saveResult = document.saveAsCompressOptimize("savePath", CPDFDocument.PDFDocumentCompressLevel.MEDIUM, new CPDFDocument.CompressListener() {
@Override
public void onUpdate(int pageIndex) {
// The page index value for monitoring the current compression progress
}
});
} catch (CPDFDocumentException e) {
}
kotlin
CPDFDocument document = CPDFDocument(context)
document.open("xxx.pdf")
// Compress & Optimize a PDF File
try {
val saveResult = document.saveAsCompressOptimize(
"savePath",
CPDFDocument.PDFDocumentCompressLevel.HIGH){pageIndex ->
// The page index value for monitoring the current compression progress
}
} catch (CPDFDocumentException e) {
}