### Install pymupdf-fonts Source: https://github.com/pymupdf/pymupdf-fonts/blob/master/README.md Command to install the pymupdf-fonts package via pip. This package is version-independent and provides the necessary font assets for PyMuPDF. ```bash python -m pip install pymupdf-fonts ``` -------------------------------- ### Install PyMuPDF Fonts Source: https://context7.com/pymupdf/pymupdf-fonts/llms.txt Installs the pymupdf-fonts package via pip to enable automatic font support within PyMuPDF applications. ```bash pip install pymupdf-fonts ``` -------------------------------- ### Load Fonts with fitz.Font Source: https://context7.com/pymupdf/pymupdf-fonts/llms.txt Demonstrates how to initialize font objects using font codes directly within the PyMuPDF Font constructor for text rendering. ```python import fitz doc = fitz.open() page = doc.new_page() # Load fonts using font codes fira_font = fitz.Font("figo") space_font = fitz.Font("spacemo") noto_font = fitz.Font("notos") writer = fitz.TextWriter(page.rect) writer.append((50, 100), "Hello in FiraGO Regular", font=fira_font, fontsize=14) writer.append((50, 130), "Hello in Space Mono", font=space_font, fontsize=14) writer.append((50, 160), "Hello in Noto Sans", font=noto_font, fontsize=14) writer.write_text(page) doc.save("fonts_demo.pdf") doc.close() ``` -------------------------------- ### Register and Use Custom Fonts in PyMuPDF Source: https://github.com/pymupdf/pymupdf-fonts/blob/master/README.md Demonstrates how to initialize a custom font using its code identifier and register it with a PDF page for text insertion. This allows developers to use extended font sets like Fira or Noto within PyMuPDF's TextWriter or page insertion methods. ```python import fitz # Initialize the font using its identifier font = fitz.Font("FiraGO-Regular") # Register the font buffer to the page page.insert_font(fontname="F0", fontbuffer=font.buffer) # Insert text using the registered font page.insert_text(point, "Hello World", fontname="F0", fontsize=12) ``` -------------------------------- ### Create Font Objects with fitzfont Source: https://context7.com/pymupdf/pymupdf-fonts/llms.txt Uses the fitzfont() convenience method to retrieve a ready-to-use fitz.Font object directly from a font code. ```python from pymupdf_fonts import fitzfont import fitz ubuntu_font = fitzfont("ubuntu") cascadia_font = fitzfont("cascadia") doc = fitz.open() page = doc.new_page() writer = fitz.TextWriter(page.rect) writer.append((50, 100), "Ubuntu font example", font=ubuntu_font, fontsize=16) writer.append((50, 140), "Cascadia Mono example", font=cascadia_font, fontsize=16) writer.write_text(page) doc.save("fitzfont_demo.pdf") doc.close() ``` -------------------------------- ### Create Styled Documents with Ubuntu Font Family Source: https://context7.com/pymupdf/pymupdf-fonts/llms.txt Illustrates how to apply different weights and styles (bold, italic, mono) from the Ubuntu font family to create a structured, professional document. It highlights the use of monospaced fonts for code snippets within a document. ```python import fitz doc = fitz.open() page = doc.new_page() # Load Ubuntu font family ubuntu_regular = fitz.Font("ubuntu") ubuntu_bold = fitz.Font("ubuntubo") ubuntu_italic = fitz.Font("ubuntuit") ubuntu_bold_italic = fitz.Font("ubuntubi") ubuntu_mono = fitz.Font("ubuntm") writer = fitz.TextWriter(page.rect) # Document title writer.append((50, 80), "Document Title", font=ubuntu_bold, fontsize=24) # Subtitle in italic writer.append((50, 115), "A subtitle in italic style", font=ubuntu_italic, fontsize=14) # Body text writer.append((50, 160), "Regular body text for the main content of your document.", font=ubuntu_regular, fontsize=12) # Emphasized text writer.append((50, 185), "Bold italic for strong emphasis.", font=ubuntu_bold_italic, fontsize=12) # Code sample writer.append((50, 230), "Code example:", font=ubuntu_bold, fontsize=12) writer.append((50, 255), "def hello(): print('Hello, World!')", font=ubuntu_mono, fontsize=11) writer.write_text(page) doc.save("styled_document.pdf") doc.close() ``` -------------------------------- ### Render Multilingual Text with FiraGO in PyMuPDF Source: https://context7.com/pymupdf/pymupdf-fonts/llms.txt Demonstrates how to use the FiraGO font to render diverse scripts including Latin, Cyrillic, Greek, and Hebrew in a PDF document. It utilizes the fitz.TextWriter class to manage text placement and font assignment. ```python import fitz doc = fitz.open() page = doc.new_page() # Load FiraGO which supports many scripts font = fitz.Font("figo") writer = fitz.TextWriter(page.rect) y = 80 # Latin script writer.append((50, y), "English: Hello World", font=font, fontsize=14) y += 30 # Cyrillic script writer.append((50, y), "Russian: Привет мир", font=font, fontsize=14) y += 30 # Greek script writer.append((50, y), "Greek: Γειά σου κόσμε", font=font, fontsize=14) y += 30 # Hebrew script (RTL) writer.append((50, y), "Hebrew: שלום עולם", font=font, fontsize=14) writer.write_text(page) doc.save("multilingual.pdf") doc.close() ``` -------------------------------- ### Query Font Metadata Source: https://context7.com/pymupdf/pymupdf-fonts/llms.txt Accesses the fontdescriptors dictionary to retrieve detailed information about fonts, such as glyph counts, style attributes, and file sizes. ```python from pymupdf_fonts import fontdescriptors info = fontdescriptors["figo"] print(f"Font: {info['name']}") print(f"Monospaced: {info['mono']}") # List all available monospaced fonts mono_fonts = [code for code, desc in fontdescriptors.items() if desc['mono']] print(f"Monospaced fonts: {mono_fonts}") ``` -------------------------------- ### Add Mathematical and Musical Symbols with Noto Fonts Source: https://context7.com/pymupdf/pymupdf-fonts/llms.txt Shows how to incorporate specialized scientific and musical notation into a PDF using Noto Math and Noto Music fonts. This snippet demonstrates loading multiple font resources simultaneously to handle different character sets. ```python import fitz doc = fitz.open() page = doc.new_page() # Load specialized symbol fonts math_font = fitz.Font("math") music_font = fitz.Font("music") regular_font = fitz.Font("notos") writer = fitz.TextWriter(page.rect) # Mathematical expressions using Noto Sans Math writer.append((50, 80), "Mathematical symbols:", font=regular_font, fontsize=12) writer.append((50, 110), "∑ ∏ ∫ ∂ ∇ √ ∞ ≠ ≤ ≥ ± × ÷", font=math_font, fontsize=16) # Musical notation using Noto Music writer.append((50, 160), "Musical symbols:", font=regular_font, fontsize=12) writer.append((50, 190), "𝄞 𝄢 𝅗𝅥 𝅘𝅥 𝅘𝅥𝅮 𝅘𝅥𝅯 𝄀 𝄁", font=music_font, fontsize=24) writer.write_text(page) doc.save("symbols.pdf") doc.close() ``` -------------------------------- ### Insert text with custom font in PyMuPDF Source: https://github.com/pymupdf/pymupdf-fonts/blob/master/README.md Demonstrates how to use the insert_textbox method in PyMuPDF to render text using a specific font identifier. The fontname parameter corresponds to the keys defined in the font registry. ```python import fitz doc = fitz.open() page = doc.new_page() rect = fitz.Rect(50, 50, 200, 100) text = "Hello World" # Using a font identifier from the registry page.insert_textbox(rect, text, fontname="figo") ``` -------------------------------- ### Access Raw Font Buffers Source: https://context7.com/pymupdf/pymupdf-fonts/llms.txt Retrieves raw font bytes using the myfont() function, allowing for custom PDF insertion methods or direct buffer usage in PyMuPDF. ```python from pymupdf_fonts import myfont import fitz fontbuffer = myfont("spacemo") doc = fitz.open() page = doc.new_page() page.insert_font(fontname="SpaceMono", fontbuffer=fontbuffer) page.insert_text( point=(72, 100), text="Text using Space Mono font buffer", fontname="SpaceMono", fontsize=12 ) doc.save("buffer_demo.pdf") doc.close() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.