Subset fonts

On this page

Not optimized files may contain embedded fonts. GroupDocs.Viewer can remove unused instructions in embedded fonts to reduce the file size.

To subset fonts in a PDF file, set the subset_fonts property to True.

The following code snippet shows how to subset fonts in a PDF file:

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions, PdfOptimizationOptions

def subset_fonts():
    # Load document
    with Viewer("sample.docx") as viewer:
        viewOptions = PdfViewOptions("subset_fonts/subset_fonts.pdf")
        viewOptions.pdf_optimization_options = PdfOptimizationOptions()
        viewOptions.pdf_optimization_options.subset_fonts = True

        viewer.view(viewOptions)

if __name__ == "__main__":
    subset_fonts()

sample.docx is the sample file used in this example. Click here to download it.

Binary file (PDF, 344 KB)

Download full output

The following image demonstrates the result. There is no difference in appearance:

No difference in appearance

But there is the significant difference in size:

Significant difference in size

On this page

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.