PDFOne .NET
Powerful all-in-one PDF library for .NET
Compatibility
VS 2005/2008/2010/2012/2013

Embed and Replace Fonts In PDF Documents

PDFOne .NET now supports embedding fonts both in creation mode as well as reading mode.
By Raju Sinha

Until recently, PDFOne .NET supported font embedding only in creation mode. In Version 1.43, methods to enable font embedding in reading mode as well were introduced. One of the methods provides the ability to replace a font existing in the document with another font that will be embedded in its place. In this article, we will see how to use these methods.

Embedding Fonts In PDF Documents

To embed a font, we need to first create a PDF font object with a font file present on the system. The font can then be embedded with the new PDFDocument.EmbedFont(PDFFont fontToBeEmbedded) method.

PDFDocument doc = new PDFDocument();
doc.Load("DocWithoutEmbeddedFont.pdf");
Font fnt = new Font("Garamond", 24);
PDFFont pfnt = new PDFFont(fnt, PDFFontEmbedType.Full);
doc.EmbedFont(pfnt);
doc.OpenAfterCreate = true;
doc.Save("DocWithEmbeddedFont.pdf");
doc.Close();

Replacing an Existing Font

Again, when you try to replace a font, you need to create the PDF font object with the PDFFontEmbedType.Full setting. Next, you embed the font using another overloaded method PDFDocument.EmbedFont(PDFFont fontToBeEmbedded, string originalFont) where you can specify the font that needs to be replaced.

PDFDocument doc = new PDFDocument();
doc.Load("DocWithoutEmbeddedFont.pdf");
Font wf = new Font("Segoe UI", 24);
PDFFont pf = new PDFFont(wf, PDFFontEmbedType.Full);
doc.EmbedFont(pf, "Garamond"); 
doc.OpenAfterCreate = true;
doc.Save("DocWithReplacedFont.pdf");
doc.Close();

---o0O0o---

Our .NET Developer Tools
Gnostice Document Studio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
Gnostice Document Studio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
Gnostice Document Studio Java

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2024 Gnostice Information Technologies Private Limited. All rights reserved.