How do I print a text file in .net
27,535
Solution 1
Have a look at this example on how to print files with VB.Net: MSDN How to: Print a Multi-Page Text File in Windows Forms
The most important class you need is PrintDocument. No third party tools or Dll's other than in System.Drawing and System.IO Namespace in .Net-Framework(> 1.1) are needed.
Solution 2
See How to print batch file in vb.net?. There's a VB.NET code sample which you should be able to use verbatim.
If you don't already know how to pull text out of a file, use File.ReadAllText
, like this:
Imports System.IO
Dim path As String = "c:\temp\MyTest.txt"
RawPrinterHelper.SendStringToPrinter("WindowsPrinterName", File.ReadAllText(path))
RawPrinterHelper
is the class described in the other question linked above. "WindowsPrinterName" is the name of the printer you want to print to.
![Connor Albright](https://i.stack.imgur.com/4oDPP.jpg?s=256&g=1)
Author by
Connor Albright
Updated on July 09, 2022Comments
-
Connor Albright almost 2 years
How do I print a .txt file in vb.net? Hopefully without using any third parties.