Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C# .NET: GDI / Druckerschriftarten verwenden in .NET

Empfohlene Antworten

Veröffentlicht

Hallo Liebe Gemeinde,

also eine kurze Vorgeschichte:

Vielleicht habt ihr eine Bessere Lösung :-)

Warum als Zitat? Nicht jeden interessiert es :D

Ich entwickle ein Kassensystem, das Bons ausdruckt. Wenn ich ganz normal das Dokument ausdrucke, kommen immer, bei jedem Beleg 3 cm mit raus. Ist eigentlich nicht so schlimm. Blos wenn man jetzt etwas druckt, was nur eine Zeile hat, ist der Feed (Leeres Papier) mehr wie der Text. Das Problem liegt darin, dass der Schneider Pysikalisch über dem Farbband liegt.

Das soll sich ändern.

Es ist so, dass wenn ich drucke ich mehrere kleine Belege drucke und somit etwas Logik reinbringen kann. Der erste beleg hat immer einen Feed, aber das ist OK.

Kleine Dumme Sache: Ich muss, wenn ich drucken will, folgendermaßen drucken:

Dokument A

Die ersten drei CM von Dokument B

CUT

Rest von Dokument B

Es gibt 2 Möglichkeiten:

Möglichkeit 1:

Ich kann Es wirklich so machen, wie ich es gesagt hab (Dokument A, 3 cm Dokument B, nur CUT schicken ohne nichts, rest von B, usw.)

Möglichkeit 2 (Die Bessere)

Ich mach ein "riesen" Dokuement wo zwischendrin, wo es nötig ist, sich ein CUT Befehl befindet. Theoretisch klappts, mit OpenOffice Word Dokuemnt Praktisch auch :-)

Nun zum Problem:

C# .NET Tools (GDI+) unterstützen keine Schriftarten, die sich auf dem Drucker befinden.

Also muss man da "Hybridmäßig" rangehen. In etwa so:

void print_Page2(object sender, PrintPageEventArgs e)

        {

            SolidBrush brush = new SolidBrush(Color.Black);

            e.Graphics.DrawString("GDI Test", new Font("control", 10), brush, 10, 10);


            IntPtr hdc = e.Graphics.GetHdc();


            LOGFONT lf = new LOGFONT();

            lf.lfCharSet = 1;

            lf.lfFaceName = "control";

            GDI.SelectObject(hdc, GDI.CreateFontIndirect(ref lf));

            GDI.TextOut(hdc, 0, 0, "@gs V", 5);


            e.Graphics.ReleaseHdc(hdc);

        }
LOGFONT.cs
    public class LOGFONT

    {

        public int lfHeight = 0;

        public int lfWidth = 0;

        public int lfEscapement = 0;

        public int lfOrientation = 0;

        public int lfWeight = 0;

        public byte lfItalic = 0;

        public byte lfUnderline = 0;

        public byte lfStrikeOut = 0;

        public byte lfCharSet = 0;

        public byte lfOutPrecision = 0;

        public byte lfClipPrecision = 0;

        public byte lfQuality = 0;

        public byte lfPitchAndFamily = 0;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]

        public string lfFaceName = string.Empty;

    }


    public static class GDI

    {


        [DllImport("gdi32.dll", ExactSpelling = true, PreserveSig = true, SetLastError = true)]

        public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);


        [DllImport("gdi32.dll")]

        public static extern IntPtr CreateFontIndirect([In] ref LOGFONT lplf);


        [DllImport("gdi32.dll")]

        public static extern bool TextOut(IntPtr hdc, int nXStart, int nYStart, string lpString, int cbString);

    }

Praktisch funktioniert es leider nicht.

Wer kann mir weiterhelfen?

Sind die Signaturen falsch?

Ist meine Idee völliger Quatsch?

Vielen Dank :-)

Liebe Grüße

errox

Hast Du das StructLayoutAttribut auf Deiner LOGFONT Klasse gesetzt? Sollte so aussehen: [structLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]

Ansonsten können wir hier nur raten, denn "Praktisch funktioniert es leider nicht" ist nicht sehr hilfreich...

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.