Skip to content
Guides

Compress and Optimize PDF Files

The compression accuracy is controlled by setting the imageQuality parameter of the CompressFile_Init interface, and the getPageIndexDelegate parameter allows us to monitor the compression progress in real time.

Below is an example code of compression and optimization of PDF files:

c#
CPDFDocument document = CPDFDocument.InitWithFilePath("filePath");
//Image quality.
float imageQuality = 40;

//Gets a callback for the progress of document compression.
CPDFDocument.GetPageIndexDelegate getPageIndex = GetPageIndex;

//Compress a document.
IntPtr compressPtr = document.CompressFile_Init(imageQuality, getPageIndex);
bool result = document.CompressFile_Start(compressPtr, "saveFilePath");

//If you need to uncompress, you can call the following method.
document.CompressFile_Cancel(compressPtr);