pdfsharp - font embed?
Asked Answered
N

1

6

I am given a file that has some other language font. They can not download the font, so they want me to embed it in the pdf.

Now, I only have PDF Reader, so I cant edit or create a pdf file. so I decided to quickly do it in C#.NET using PDFSharp library, but I just cant seem to figure out how to embed fonts using pdfSharp?!

Also, it's only 1 file that I have to process, so if you know of a way to do it manually, then that would be great too.

Nescience answered 12/10, 2009 at 21:57 Comment(0)
M
14

There are two ways to do this. For each font you want to embed like this:

var options = new XPdfFontOptions(PdfFontEmbedding.Always);
var font = new XFont("Times New Roman", 12, XFontStyle.Regular, options);

Then if you use the font, it will get embedded.

If you want all fonts use on a page to be embedded you can do it like this:

var page = new PdfPage();
var gfx = XGraphics.FromPdfPage(page);
gfx.MFEH = PdfFontEmbedding.Automatic;

The second approach will also work for any fonts used in MigraDoc code.

Meggs answered 14/10, 2009 at 9:12 Comment(3)
Does this mean the fonts need to be installed in the server? Is there a way to point to a font file in the FS?Willianwillie
@JamesReategui Check out the following sample, as it is about "private fonts": pdfsharp.net/wiki/PrivateFonts-sample.ashxPaucker
What is this in that example?Autoerotic

© 2022 - 2024 — McMap. All rights reserved.