How to Work with Font Vendor Data in Python

How to Work with Font Vendor Data in Python

FontCleaner removes non-essential metadata from fonts to reduce file size and improve embedding compliance. It is particularly useful before deploying fonts on the web or embedding them in PDFs.

Step-by-Step Guide

Step 1: Install the Package

pip install "aspose-font>=1.0.0"

Step 2: Import Required Classes

from aspose_font.loader import FontLoader
from aspose_font.cleaner import FontCleaner

Step 3: Load the Font

font = FontLoader.open("MyFont.ttf")

Step 4: Clean the Font for Web Use

from aspose_font.loader import FontLoader
from aspose_font.cleaner import FontCleaner

font = FontLoader.open("MyFont.ttf")
cleaned = FontCleaner.clean_for_web(font, drop_mac_names=True, drop_legacy_tables=True, drop_metadata_tables=False)

The parameters control which optional table groups are removed:

  • drop_mac_names — removes legacy Mac-platform name table entries
  • drop_legacy_tables — removes pre-OpenType legacy tables
  • drop_metadata_tables — removes optional XML metadata tables

Common Issues and Fixes

FontCleaner not found — The module path is aspose_font.cleaner, not aspose_font.font_cleaner.

Cleaned font has no name — Do not set drop_mac_names=True and drop_legacy_tables=True together on fonts that rely on legacy name records for display name resolution.

Frequently Asked Questions

What does clean_for_web do?

FontCleaner.clean_for_web() returns a new Font instance with specified optional metadata tables removed. The original Font object is not modified.

Does cleaning affect glyph outlines?

No. Only metadata and auxiliary tables are affected. Glyph outline data is preserved.

See Also