1

I am trying to use a custom font with design automation when generating a pdf. Following the answer from this Stackoverflow question StackOverFlow Question, I placed the font file in the Contents folder of the bundle, and changed the PackageContents.xml to reference the Support path, but I am still getting a warning from forge Inventor inner xml: <Warning Message="Cannot create font Helvetica 35 Thin" />

Am I missing something?

1 Answers1

1

Have just written a blog post about this: https://forge.autodesk.com/blog/use-custom-fonts-design-automation

The bottom line is that you can use System.Drawing.Text.PrivateFontCollection in order to load your custom font before opening the drawing and that should make things work:

public void RunWithArguments(Document doc, NameValueMap map)
{
  LogTrace("RunWithArguments called with v7");

  string bundlePath = map.Item["_1"] as string;
  string contents = System.IO.Path.Combine(bundlePath, @"DaSamplePlugin.bundle\Contents");

  string dwgPath = IO.Path.Combine(contents, "AssetLibraryTest", "CustomFontTest.dwg");
  string fontPath = IO.Path.Combine(contents, "AssetLibraryTest", "DancingScript-Regular.ttf");

  PrivateFontCollection pfc = new PrivateFontCollection();
  pfc.AddFontFile(fontPath);

  doc = inventorApplication.Documents.Open(dwgPath, false);

  doc.SaveAs("result.pdf", true);
}
Adam Nagy
  • 1,700
  • 1
  • 9
  • 14