c# - PDFSharp WPF 1.32 private fonts will not work with Azure Blob storage -
c# - PDFSharp WPF 1.32 private fonts will not work with Azure Blob storage -
i have code adds text using private font pdf file using pdfsharp. works if font located on local file scheme not work when provide url font stored on azure blog storage. tried using google font on cdn, didn't work. there problem loading fonts web url?
the sample code below. note have solved cors issue on azure blob storage isn't that.
private readonly xpdffontoptions _fontoptions = new xpdffontoptions(pdffontencoding.unicode, pdffontembedding.always); private static readonly xprivatefontcollection privatefontcollection = xprivatefontcollection.global; [test] public async task test01rawpdfsharp() { //setup var business relationship = "labelapptest"; var fs = new filestore(account); var fonturl = "http://labelapptest.blob.core.windows.net/designernospamcom/justyna sokolowska - erazm-regular.otf"; var pdfurl = "https://labelapptest.blob.core.windows.net/label-highrez-blank/blank-label00001.pdf"; var fontfamily = "erazm regular"; var localfontpath = path.combine(testfilehelpers.gettestdatafiledirectory(@"\testfonts"), "justyna sokolowska - erazm-regular.otf"); //attempt var sfontfamilyname = "./#" + fontfamily; var uri = new uri(fonturl); privatefontcollection.add(uri, sfontfamilyname); var readdirstatus = await fs.getdirhandleasync(filestoragetypes.labelhighrezblank); using (var readstream = new memorystream()) { await readdirstatus.result.readfileasync(readstream, pdfurl); readstream.seek(0, seekorigin.begin); var document = pdfreader.open(readstream); var gfx = xgraphics.frompdfpage(document.pages[0]); var font = new xfont(fontfamily, new xunit(12, xgraphicsunit.point), xfontstyle.regular, _fontoptions); var brush = new xsolidbrush(xcolor.fromknowncolor(xknowncolor.red)); gfx.drawstring("hello world", font, brush, 10, 10); } //verify }
in illustration above if utilize fonturl
in uri adding font code fails @ line xfont created (6th bottom). if on other hand utilize localfontpath
works.
the error is: cannot matching glyph typeface font 'erazm regular'
@ line @ pdfsharp.drawing.xfont.initialize() in xfont.cs: line 234.
note: have downloaded , edited 1.32 pdfsharp code replace debugger.break
statement exception @ point. nuget version has debugger.break
causes hang in released code - see my question issue.
in end swapped pdfsharp wpf 1.50 beta font handling much improve , wasn't getting anywhere problem of loading font via http link. seems working well.
the phone call privatefontcollection.add(uri, sfontfamilyname)
passes uri new system.windows.media.fontfamily(baseuri, familyname)
. don't know whether media.fontfamily can handle uris azure storage.
we utilize privatefontcollection fonts resources - , loading fonts resources sample given in help fontfamily constructor (uri, string)
. that's type of uri known work pdfsharp.
the syntax fontfamily constructor (uri, string)
cryptic , smallest error lead "not found".
c# .net fonts azure-storage-blobs pdfsharp
Comments
Post a Comment