There are several ways to reduce the size of PDF documents through PDF Clown:

  • Compact serialization — PDF documents can be serialized retaining either the previous versions (incremental update) or the last one only (compact serialization).
    import org.pdfclown.files.File;
    import org.pdfclown.files.SerializationModeEnum;
    
    . . .
    
    File file = new File(myFilePath);
    . . .
    file.save(SerializationModeEnum.Standard); // Compact serialization.
    
  • Compressed serialization — PDF documents can be either plain (no object compression) or compressed (full object compression). Note that compressed serialization was introduced by PDF spec 1.5; therefore, if you needed to extend their compatibility to older versions, you should stick with plain compression instead.
    import org.pdfclown.files.File;
    import org.pdfclown.files.SerializationModeEnum;
    import org.pdfclown.files.XRefModeEnum;
    
    . . .
    
    File file = new File(myFilePath);
    . . .
    file.getConfiguration().setXRefMode(XRefModeEnum.Compressed); // Full object compression.
    file.save(SerializationModeEnum.Standard);
    
  • Unused objects removal — PDF documents can be optimized removing objects without references.
    import org.pdfclown.files.File;
    import org.pdfclown.files.SerializationModeEnum;
    import org.pdfclown.files.XRefModeEnum;
    import org.pdfclown.tools.Optimizer;
    
    . . .
    
    File file = new File(myFilePath);
    . . .
    Optimizer.removeOrphanedObjects(file); // Removes unused objects.
    file.getConfiguration().setXRefMode(XRefModeEnum.Compressed);
    file.save(SerializationModeEnum.Standard);
    

Your Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s