Free Support Forum - aspose.com

Embedding font in PDF

I'm trying to figure out how to embed a true type font in a pdf I'm creating. How do I do this?

I start with a word file and run it through .Words then outputting the pdf.

I'm outputting strings to the Word file with WriteLn

Is there a way I can just attach the font to the pdf and force the entire document to use that font?

Hi,

Thank you for considering Aspose.

When converting Word to Pdf, the fonts setting in Word is used in Pdf. If you want to change the font setting, you have to modify the DOM objects before save the Pdf document. Here is an example:

foreach(Aspose.Pdf.Section sec in pdf.Sections)
{
foreach(Paragraph para in sec.Paragraphs)
{
if(para is Text)
{
Text t = para as Text;
foreach(Segment seg in t.Segments)
{
seg.TextInfo.FontName = "Arial";
seg.TextInfo.IsFontEmbedded = true;
}
}
}
}

pdf.Save(...);

Ok, so I'll just set the font in the word file.

How do I embed the font in the pdf (for viewing on a computer that doesn't have the font)?

jiro

Dear Jiro,

Please note the line

seg.TextInfo.IsFontEmbedded = true;

That will make the font embedded.

What if the font isn't installed on the server? (this is a shared server and we are purchasing the font).

The server which is used to generate the PDF must have the font installed. If the font is embedded into the PDF, the PDF can be viewed without the font installed.