1

I try to add a the font "Open Sans" to my pdf file that I create with AbcPdf 7. But the font is not being used. Why is that?

Doc odfDoc = new Doc();
            odfDoc.FontSize = 216;
            string daFont = "Open Sans";
            odfDoc.Font = odfDoc.EmbedFont(daFont);
            odfDoc.AddText(daFont);
            odfDoc.Save(AppDomain.CurrentDomain.BaseDirectory + "\\font.pdf");
            odfDoc.Clear();
MTplus
  • 2,077
  • 4
  • 34
  • 51
  • Why are you adding HTML instead of text? – Mike 'Pomax' Kamermans Oct 18 '19 at 18:20
  • Beacuse I want that part to be bold – MTplus Oct 18 '19 at 18:21
  • That's... literally what fonts are for, though? Load the bold version of Open Sans and use that to add the text `"Name"`. Adding HTML means you're suddenly switching from "your" instructions to "whatever the rules for HTML elements are". – Mike 'Pomax' Kamermans Oct 18 '19 at 18:25
  • But its not open sans in any text at all on the text being rendered. Maybe I do this wrong but I thought open sans would be used if I did the way I do? – MTplus Oct 18 '19 at 18:28
  • I have no idea: you haven't shown any other code. https://www.websupergoo.com/helppdfnet/default.htm?page=source%2F5-abcpdf%2Fdoc%2F1-methods%2Fembedfont.htm shows examples of how to use this: if you copy/paste those, do they work? – Mike 'Pomax' Kamermans Oct 18 '19 at 18:34
  • If I use Comic Sans in my code it works, but not Open Sans, and I still have no clue on how to add use a specific font in one cell of the table instead of just using the same font in the whole pdf file.... – MTplus Oct 18 '19 at 18:56
  • And you actually have the real Open Sans (not the google webfont) installed? As for "how to use the font": set `myDoc.Font = ...` every time you need the font changed. PDF write operations are sequential. – Mike 'Pomax' Kamermans Oct 18 '19 at 19:30
  • I have downloaded and installed the google font open sans on my local pc – MTplus Oct 18 '19 at 19:31
  • Okay, yeah _never do that_ - Google fonts are NOT for system installation, they're highly stripped down versions of real fonts. Install the real Open Sans instead by downloading it from https://www.opensans.com/ – Mike 'Pomax' Kamermans Oct 18 '19 at 19:34
  • Sorry but that did not help either. – MTplus Oct 18 '19 at 19:51
  • 1
    Then it's time to add more details to your POST with a [mcve]: explain that your font is properly installed (e.g. wordpad etc. can see it), and minimise your code to generate the tiniest of PDF files that should reasonably speaking work fine if someone else did this same thing (similar to the example from the documentation). – Mike 'Pomax' Kamermans Oct 18 '19 at 19:54
  • Yes I have updated the code abow with the code being used that is not using Open Sans even though I have down ´loaded and installed it. – MTplus Oct 18 '19 at 20:08
  • This almost certainly is because you haven't specified the correct name for the font - often the name is different to what you think it ought to be! ABCpdf has some static XFont methods to find the correct font name which will work for your particular version (https://www.websupergoo.com/helppdfnet/default.htm?page=source%2F5-abcpdf%2Fxfont%2F1-methods%2Ffindbyname.htm). Incidentally ABCpdf version 7 was discontinued early in 2011, so you might want to consider upgrading! – Peter G Oct 21 '19 at 09:42
  • 1
    No need for upgrading, if I specified the complete path to the font it worked. – MTplus Oct 21 '19 at 12:42
  • Voting to close, since this has been solved by user for nearly two years yet they never bothered to enter an Answer for their solution. – Ross Presser Jul 20 '21 at 14:05

0 Answers0