Send string directly to a printer with interop

Belias
Member Posts: 2,998
Hi guys,
I need to directly send a string to a printer (a zebra, but it's not that important) through .net interoperability. I dug internet but what i found is this c# that i am not able to translate into nav, because there's the PrintPage event that i don't know how translate in nav. Any clue?
public void Print(string PrinterName)
{
PrintDocument doc = new PrintDocument();
doc.PrinterSettings.PrinterName = PrinterName;
doc.PrintPage += new PrintPageEventHandler(PrintHandler);
doc.Print();
}
private void PrintHandler(object sender, PrintPageEventArgs ppeArgs)
{
Font FontNormal = new Font("Verdana", 12);
Graphics g = ppeArgs.Graphics;
g.DrawString("Your string to print", FontNormal, Brushes.Black, xpos, ypos, new StringFormat());
}
Just for the record (techy stuff): why doing this stuff instead of printing a report with a single textbox to the desired zebra printer?
because i need to get this work on a webclient. Althought i worked around the fact that "webclient only prints to pdf if there's no request page" through a STARTSESSION command, i found out that doing a "REPORT.PRINT(.....)" in a start session prints a pdf and then sends the pdf to the desired printer. This screws up the text in my textbox and my zebra prints zpl code instead of the correct label.
I need to directly send a string to a printer (a zebra, but it's not that important) through .net interoperability. I dug internet but what i found is this c# that i am not able to translate into nav, because there's the PrintPage event that i don't know how translate in nav. Any clue?
public void Print(string PrinterName)
{
PrintDocument doc = new PrintDocument();
doc.PrinterSettings.PrinterName = PrinterName;
doc.PrintPage += new PrintPageEventHandler(PrintHandler);
doc.Print();
}
private void PrintHandler(object sender, PrintPageEventArgs ppeArgs)
{
Font FontNormal = new Font("Verdana", 12);
Graphics g = ppeArgs.Graphics;
g.DrawString("Your string to print", FontNormal, Brushes.Black, xpos, ypos, new StringFormat());
}
Just for the record (techy stuff): why doing this stuff instead of printing a report with a single textbox to the desired zebra printer?
because i need to get this work on a webclient. Althought i worked around the fact that "webclient only prints to pdf if there's no request page" through a STARTSESSION command, i found out that doing a "REPORT.PRINT(.....)" in a start session prints a pdf and then sends the pdf to the desired printer. This screws up the text in my textbox and my zebra prints zpl code instead of the correct label.
0
Best Answer
-
https://juhl.blog/2017/04/26/direct-print-using-net/
Maybe you can use my solution, I use it for barcode printers.Follow me on my blog juhl.blog1
Answers
-
https://juhl.blog/2017/04/26/direct-print-using-net/
Maybe you can use my solution, I use it for barcode printers.Follow me on my blog juhl.blog1
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions