Cómo gestionar fuentes en la conversión de HTML a PDF

How to Manage Fonts in PDFs

This article was translated from English: Does it need improvement?
Translated
View the article in English

A font is a set of characters, symbols, and glyphs with a consistent style and design. It represents a specific typeface, size, weight, and style (such as regular, bold, italic, etc.) of text. Fonts are used in typography to display text in a visually appealing and coherent manner.

IronPDF provides a convenient way to manage fonts, offering functionalities such as finding fonts, getting fonts, embedding fonts, unembedding fonts, and replacing fonts.

Quickstart: Manage and Embed Fonts in Your PDF

Get started with IronPDF to streamline font management in your PDF documents. This quick guide demonstrates how to embed all fonts in a PDF to ensure visual consistency across different platforms. With just a few lines of code, you can enhance your PDF documents' appearance and maintain compatibility without additional font installations.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    var pdf = PdfDocument.FromHtml("<p style='font‑family:MyCustomFont;'>Hello world!</p>");
    pdf.Fonts.Add("MyCustomFont", File.ReadAllBytes("MyCustomFont.ttf"))
      .Embed()
      .SaveAs("withCustomFont.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

Find and Retrieve Font

Retrieve Font

Accessing the Fonts property will return the PdfFontCollection object, which contains the list of all the fonts in the document. The Fonts property can be accessed directly by iterating over the PdfFontCollection object.

:path=/static-assets/pdf/content-code-examples/how-to/manage-font-retrieve-font.cs
using IronPdf;
using IronPdf.Fonts;
using System.Collections.Generic;

// Import PDF
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

// Retreive font
PdfFontCollection fonts = pdf.Fonts;
Imports IronPdf
Imports IronPdf.Fonts
Imports System.Collections.Generic

' Import PDF
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")

' Retreive font
Private fonts As PdfFontCollection = pdf.Fonts
$vbLabelText   $csharpLabel

Find Font

Finding a specific font is straightforward with IronPDF. Using the PdfFontCollection object, you can specify the font name. This example shows how to access a font object by name and inspect properties.

:path=/static-assets/pdf/content-code-examples/how-to/manage-font-find-font.cs
using IronPdf;
using IronPdf.Fonts;
using System.Collections.Generic;
using System.Linq;

// Import PDF
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

// Find font
PdfFont font = pdf.Fonts["SpecialFontName"];
Imports IronPdf
Imports IronPdf.Fonts
Imports System.Collections.Generic
Imports System.Linq

' Import PDF
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")

' Find font
Private font As PdfFont = pdf.Fonts("SpecialFontName")
$vbLabelText   $csharpLabel

Add Font

Use the Add method to add both a standard font and a font file as byte data. The method accepting the font name only accepts one of the 14 standard fonts. Adding a standard font does not embed it, as the standard font is already guaranteed to be available on the operating system.

:path=/static-assets/pdf/content-code-examples/how-to/manage-font-add-font.cs
using IronPdf;
using IronPdf.Fonts;

// Import PDF
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

// Add font
pdf.Fonts.Add("Helvetica");
Imports IronPdf
Imports IronPdf.Fonts

' Import PDF
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")

' Add font
pdf.Fonts.Add("Helvetica")
$vbLabelText   $csharpLabel

Embed Font

Embedding a font means including a font’s byte stream data in the PDF document itself. This way, it doesn't require the font to be installed on the system to view the PDF document properly. While this generally increases the file size of the PDF document, it's beneficial for visual consistency without the additional requirement of installing the font.

:path=/static-assets/pdf/content-code-examples/how-to/manage-font-embed-font.cs
using IronPdf;
using System.Linq;

// Import PDF
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

// Add the font
byte[] fontData = System.IO.File.ReadAllBytes("dir/to/font.ttf");

// Embed the font
pdf.Fonts.Last().Embed(fontData);
Imports IronPdf
Imports System.Linq

' Import PDF
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")

' Add the font
Private fontData() As Byte = System.IO.File.ReadAllBytes("dir/to/font.ttf")

' Embed the font
pdf.Fonts.Last().Embed(fontData)
$vbLabelText   $csharpLabel

Unembed Font

Unembedding a font means removing the embedded byte stream data of the font included in a PDF document. The goal is to reduce the PDF document's file size. Use the Unembed method to achieve this.

:path=/static-assets/pdf/content-code-examples/how-to/manage-font-unembed-font.cs
using IronPdf;
using IronPdf.Fonts;

// Import PDF
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

// Get fonts
PdfFontCollection fonts = pdf.Fonts;

// Unembed a font
pdf.Fonts[0].Unembed();
Imports IronPdf
Imports IronPdf.Fonts

' Import PDF
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")

' Get fonts
Private fonts As PdfFontCollection = pdf.Fonts

' Unembed a font
pdf.Fonts(0).Unembed()
$vbLabelText   $csharpLabel

If a font in the original document is too uncommon or lacks a fallback, it may appear corrupted in the output PDF after the fonts are unembedded. You can troubleshoot this by checking if unembedding the same font in Adobe causes the same problem. If the issue also happens in Adobe, this is expected behavior. However, if it does not, please report the issue to our support team for further investigation. The corrupted font appear like the following:

Corrupted font PDF

Replace Font

The font replacement operation will preserve the original font data structure, such as styling and character encoding, inside a PDF document but replace it with a newly specified font. Users must ensure that the new font aligns well with the original font.

AdvertenciaIn some rare cases, the resulting visual may not be a perfect fit. This is a current limitation of the font replacement method.

:path=/static-assets/pdf/content-code-examples/how-to/manage-font-replace-font.cs
using IronPdf;
using IronPdf.Fonts;
using System.Linq;

// Import PDF
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

byte[] fontData = System.IO.File.ReadAllBytes("dir/to/font.ttf");
// Get and replace Font
pdf.Fonts["Courier"].ReplaceWith(fontData);
Imports IronPdf
Imports IronPdf.Fonts
Imports System.Linq

' Import PDF
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")

Private fontData() As Byte = System.IO.File.ReadAllBytes("dir/to/font.ttf")
' Get and replace Font
pdf.Fonts("Courier").ReplaceWith(fontData)
$vbLabelText   $csharpLabel

Standard Fonts

The 14 standard fonts in PDF, also known as the 'Base 14 Fonts' or 'Standard Type 1 Fonts,' form a set of fonts that are widely supported in PDF viewers and do not need to be embedded in the document. Standard fonts define 14 fonts that are guaranteed (as per the PDF document standard) to be available when working with a PDF document.

  • Courier
  • Courier-Bold
  • Courier-Oblique
  • Courier-BoldOblique
  • Helvetica
  • Helvetica-Bold
  • Helvetica-Oblique
  • Helvetica-BoldOblique
  • Times-Roman
  • Times-Bold
  • Times-Italic
  • Times-BoldItalic
  • Symbol
  • ZapfDingbats

Standard Fonts Mapping

For convenience when referring to the standard fonts, multiple string names point to the same font.

Map to Courier

  • StandardFont.Courier
    • Courier
    • CourierNew
    • CourierNewPSMT
    • CourierStd

Map to Courier-Bold

  • StandardFont.CourierBold
    • Courier,Bold
    • Courier-Bold
    • CourierBold
    • CourierNew,Bold
    • CourierNew-Bold
    • CourierNewBold
    • CourierNewPS-BoldMT
    • CourierStd-Bold

Map to Courier-Oblique

  • StandardFont.CourierOblique
    • Courier,Italic
    • Courier-Oblique
    • CourierItalic
    • CourierNew,Italic
    • CourierNew-Italic
    • CourierNewItalic
    • CourierNewPS-ItalicMT
    • CourierStd-Oblique

Map to Courier-BoldOblique

  • StandardFont.CourierBoldOblique
    • Courier,BoldItalic
    • Courier-BoldOblique
    • CourierBoldItalic
    • CourierNew,BoldItalic
    • CourierNew-BoldItalic
    • CourierNewBoldItalic
    • CourierNewPS-BoldItalicMT
    • CourierStd-BoldOblique

Map to Helvetica

  • StandardFont.Helvetica
    • Arial
    • ArialMT
    • Helvetica

Map to Helvetica-Bold

  • StandardFont.HelveticaBold
    • Arial,Bold
    • Arial-Bold
    • Arial-BoldMT
    • ArialBold
    • ArialMT,Bold
    • ArialRoundedMTBold
    • Helvetica,Bold
    • Helvetica-Bold
    • HelveticaBold

Map to Helvetica-Oblique

  • StandardFont.HelveticaOblique
    • Arial,Italic
    • Arial-Italic
    • Arial-ItalicMT
    • ArialItalic
    • ArialMT,Italic
    • Helvetica,Italic
    • Helvetica-Italic
    • Helvetica-Oblique
    • HelveticaItalic

Map to Helvetica-BoldOblique

  • StandardFont.HelveticaBoldOblique
    • Arial,BoldItalic
    • Arial-BoldItalic
    • Arial-BoldItalicMT
    • ArialBoldItalic
    • ArialMT,BoldItalic
    • Helvetica,BoldItalic
    • Helvetica-BoldItalic
    • Helvetica-BoldOblique
    • HelveticaBoldItalic

Map to Times-Roman

  • StandardFont.Times
    • Times-Roman
    • TimesNewRoman
    • TimesNewRomanPS
    • TimesNewRomanPSMT

Map to Times-Bold

  • StandardFont.TimesBold
    • Times-Bold
    • TimesBold
    • TimesNewRoman,Bold
    • TimesNewRoman-Bold
    • TimesNewRomanBold
    • TimesNewRomanPS-Bold
    • TimesNewRomanPS-BoldMT
    • TimesNewRomanPSMT,Bold

Map to Times-Italic

  • StandardFont.TimesOblique
    • Times-Italic
    • TimesItalic
    • TimesNewRoman,Italic
    • TimesNewRoman-Italic
    • TimesNewRomanItalic
    • TimesNewRomanPS-Italic
    • TimesNewRomanPS-ItalicMT
    • TimesNewRomanPSMT,Italic

Map to Times-BoldItalic

  • StandardFont.TimesBoldOblique
    • Times-BoldItalic
    • TimesBoldItalic
    • TimesNewRoman,BoldItalic
    • TimesNewRoman-BoldItalic
    • TimesNewRomanBoldItalic
    • TimesNewRomanPS-BoldItalic
    • TimesNewRomanPS-BoldItalicMT
    • TimesNewRomanPSMT,BoldItalic

Map to Symbol

  • StandardFont.Symbol
    • Symbol
    • SymbolMT

Map to ZapfDingbats

  • StandardFont.Dingbats
    • ZapfDingbats

Preguntas Frecuentes

¿Cómo puedo encontrar y listar las fuentes usadas en un documento PDF?

Puedes usar IronPDF para acceder a la propiedad Fonts de un objeto PdfDocument, que proporciona una PdfFontCollection. Iterar sobre esta colección te permite encontrar y listar todas las fuentes usadas en el documento.

¿Qué métodos están disponibles para agregar fuentes a un PDF?

IronPDF te permite agregar fuentes usando el método Add, que puede incluir fuentes estándar o archivos de fuentes personalizados como datos en bytes. Este método te permite extender la gama de fuentes disponibles en tus documentos PDF.

¿Cómo se incrustan fuentes en un PDF para asegurar la consistencia visual?

Para incrustar fuentes usando IronPDF, puedes recuperar la fuente deseada de la PdfFontCollection y aplicar el método Embed. Esto asegura que los datos de flujo de bytes de la fuente estén incluidos en el PDF, manteniendo la consistencia visual en diferentes sistemas.

¿Por qué desincrustar una fuente en un documento PDF?

Desincrustar una fuente con IronPDF implica eliminar los datos de flujo de bytes incrustados para reducir el tamaño del archivo. Esto es útil cuando el tamaño del archivo es una prioridad y la fuente está comúnmente disponible en la mayoría de los sistemas.

¿Cuál es el proceso para reemplazar una fuente en un PDF?

Puedes reemplazar una fuente en un PDF usando el método Replace de IronPDF dentro de la PdfFontCollection. Esto te permite sustituir una fuente existente por otra, asegurando que coincida con el estilo y la codificación del original lo más cerca posible.

¿Por qué son importantes las Fuentes Base 14 en PDFs?

Las Fuentes Base 14, o Fuentes Tipo 1 Estándar, como Courier, Helvetica y Times-Roman, son cruciales porque son universalmente compatibles con los visores de PDF. No necesitan ser incrustadas, asegurando compatibilidad y reduciendo el tamaño del archivo.

¿Es posible usar fuentes personalizadas en documentos PDF?

Sí, IronPDF admite la inclusión de fuentes personalizadas. Usando el método Add con datos de archivo de fuente, puedes incorporar cualquier fuente en tu documento PDF más allá de las opciones estándar.

¿Cuáles son las ventajas de gestionar fuentes en documentos PDF usando IronPDF?

IronPDF ofrece capacidades robustas de gestión de fuentes, permitiéndote encontrar, agregar, incrustar, desincrustar y reemplazar fuentes. Esta flexibilidad mejora la personalización del documento y asegura consistencia visual en varias plataformas.

¿IronPDF es totalmente compatible con .NET 10 para operaciones de gestión de fuentes?

Sí. IronPDF ofrece compatibilidad total con .NET 10 y admite todas las operaciones de administración de fuentes (incluidas Add , Embed , Unembed , Replace y acceder a fuentes estándar) sin necesidad de soluciones alternativas ni configuraciones especiales.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado