Share via

Device Font for WPF Application

frankborty 41 Reputation points
2022-06-23T09:47:16.46+00:00

I'm developing a WPF application (.NET FW 4.5) based on the idea to create a simple layout (text, shapes, pictures) for a specific printer device (using paper size, margin, color or b/n, etc).

I'm struggling with device fonts. For example, Zebra printers could use particular fonts which is not installed on the OS but only on the printer itself (or the driver, I'm not sure about this).
Is there a way to use device font in a WPF Application?
How can I enumerate the fonts supported by a specific printer?

Developer technologies | Windows Presentation Foundation
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Castorix31 91,876 Reputation points
    2022-06-23T10:10:41.363+00:00

    It is explained in MSDN at Use printer device fonts
    You can use the same code in C# with P/Invoke ...

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. frankborty 41 Reputation points
    2022-06-27T21:20:37.353+00:00

    Thank you for suggestion I used a very similar solution and now I'm able to collect all the font supported by devices.

    Now I want to use the font in my WPF application.
    I tried to use the following function:

    Font newFont = Font.FromLogFont(myLogFont, hdcHandle);   
    //myLogFont is the LOGFONT structure assocated with device font  
    //hdcHandle is the HANDLE to printer device context  
    

    FromLogFont throws an exception because myLogFont is not of TrueType font.

    Is there a way to use non TrueType font in WPF?

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.