c# - Drawing text using font from file not working -
i'm trying load private font, using system.drawing.text.privatefontcollection. the goal not have install font on system.
all examples find pretty simple. load using privatefontcollection , create font it.
below simple class test it.
it works if install font. in not, text printed in dialog preview using default font. checked font correctly loaded. i'm missing ? thank help.
public partial class test : form { private printdocument printdocument1 = new printdocument(); system.drawing.text.privatefontcollection privatefonts; private font _barcodefont; public test() { initializecomponent(); } private void test_load(object sender, eventargs e) { privatefonts = new system.drawing.text.privatefontcollection(); privatefonts.addfontfile("code128.ttf"); } private void btbtest_click(object sender, eventargs e) { printdocument pd = new printdocument(); pd.printpage += new printpageeventhandler(this.pd_printpage); pd.documentname = "label"; printpreviewdialog pp = new printpreviewdialog(); pp.document = pd; pp.windowstate = formwindowstate.normal; pp.showdialog(); } private void pd_printpage(object sender, printpageeventargs ev) { _barcodefont = new font(privatefonts.families[0], 12, fontstyle.regular); ev.graphics.drawstring("should bar code", _barcodefont, brushes.black, 0, 0); ev.hasmorepages = false; } }
try this
private void pd_printpage(object sender, printpageeventargs ev) { font _barcodefont = new font(privatefonts.families[0], 12, fontstyle.regular); ev.graphics.drawstring("should bar code", _barcodefont, brushes.black, 0, 0); ev.hasmorepages = false; }
, remove
private font _barcodefont;
Comments
Post a Comment