Compact and compress the document.




void Compact(bool wholeDocument)
[Visual Basic]
Function Compact(wholeDocument As Boolean)

Throws Exceptions may throw Exception()



Name Description
wholeDocument Whether to compact the entire document or only selected pages.




Compact and compress the document.

The two main types of resources which take up file space are images and embedded fonts. As such this method allows you to resize images to a lower resolution, compress them using different methods and quality settings and remove embedded fonts. The particular options appropriate to your documents can be set using the properties on this operation.

During processing ProcessingObject and ProcessedObject events will be fired for each font or image object that is being operated upon. Using the arguments included with these events you can take finer control over the application of this operation.

If you have previously added content to the document it will need to be frozen in place. This may result in changes to the Doc.HtmlOptions, Doc.Rendering and Doc.SaveOptions properties.

You may also wish to set the SaveOptions.CompressObects property to true, to further reduce the output size on save.

This type of operations is fairly complex and can take some time on larger documents.




The following example shows how to compress a document.


using (Doc doc = new Doc()) {   doc.Read(Server.MapPath("../mypics/sample.pdf"));   using (ReduceSizeOperation op = new ReduceSizeOperation(doc))     op.Compact(true);   doc.Save(Server.MapPath("ReduceSizeOperation.pdf")); }