Print Word Document in Dot Matrix Printer with Printer Default Font
-
Wednesday, April 21, 2010 3:20 AM
hi i m using this this coding to copy and print the word document
System.IO.File.Copy(Application.StartupPath & "\PrintT.doc", Application.StartupPath & "\PrintT1.doc", True) Dim line1 As String Dim line2 As String line1 = "Line1 Replace" line2 = "Line2 Replace" Dim objWordApp As New Word.Application objWordApp.Visible = True 'Open an existing document. Dim objDoc As Word.Document = objWordApp.Documents.Open(Application.StartupPath & "\PrintT1.doc") objDoc = objWordApp.ActiveDocument 'Find and replace some text 'Replace 'VB' with 'Visual Basic' objDoc.Content.Find.Execute(FindText:="Line1",ReplaceWith:=line1, Replace:=Word.WdReplace.wdReplaceAll) objDoc.Content.Find.Execute(FindText:="Line2", ReplaceWith:=line2, Replace:=Word.WdReplace.wdReplaceAll) objDoc.Content.Find.Execute(FindText:="Line3", ReplaceWith:="Line3 Replace", Replace:=Word.WdReplace.wdReplaceAll) 'Save and close the document 'objDoc.Save() objDoc.PrintOut(True, True) objDoc.Close() objDoc = Nothing objWordApp.Quit() objWordApp = Nothing
now i need to print the Word Document with Printer Default Font(Draft 17.5 CPI) in Dot Matricx Printer
All Replies
-
Friday, April 23, 2010 9:14 AMModerator
Hi sivakl,
You can easily to print an external document using Process.Start method in VB.NET like this:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim psi As New ProcessStartInfo
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
'psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()
psi.FileName = "C:\MyFile.doc" ' Here specify a document to be printed
Process.Start(psi)
End Sub
End Class
Best regards,
Martin Xie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer by Martin_XieModerator Thursday, April 29, 2010 3:58 AM
-
Monday, January 03, 2011 3:58 PM
Hello
I didnt use Escape Char because of i dont know how i can use it. I use dotmatrix printer.
My Turkish characters like ğ, ü, ş,ç,ö,ı doesnt look good at paper. It is big problem for me. What can i do for this ? Can you give me csharp codes ? Also my Line 4 doesnt print now. What can be problem ?
My txt file create codes and print codes like below.
System.IO.FileStream file; file= System.IO.File.Create(Application.StartupPath + "\\test.txt"); file.Close(); StreamWriter theWriter = new StreamWriter(Application.StartupPath + "\\test.txt"); string INITPRINTER = string.Format("{0}@", (char)27);//complete print. string word = "Line1 üşiıçöğ"; theWriter.Write(word.PadRight(20)); string word1 = "Satır 1"; theWriter.Write(word1); for (int x = 0; x < 4; x++) //Row is 4 { theWriter.WriteLine(); } theWriter.Write("Line 4");// Row is 4. Line 4 doesnt print. Why ? theWriter.Write(INITPRINTER); // and at the end to reset theWriter.Close(); CMDProcess a = new CMDProcess(); a.printfile("/C copy test.txt LPT1"); class CMDProcess { // These are the Win32 error codes for file // not found or access denied const int ERROR_FILE_NOT_FOUND = 2; const int ERROR_ACCESS_DENIED = 5; public void printfile(string arg) { Process myProcess = new Process(); try { myProcess.StartInfo.FileName = "cmd.exe"; myProcess.StartInfo.Arguments = arg; myProcess.StartInfo.CreateNoWindow = false; myProcess.StartInfo.UseShellExecute = true; myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; myProcess.Start(); } catch (Win32Exception e) { if (e.NativeErrorCode == ERROR_FILE_NOT_FOUND) { MessageBox.Show(e.Message + ". Dosya bulunamadı."); } else if (e.NativeErrorCode == ERROR_ACCESS_DENIED) { MessageBox.Show(e.Message + ". Erişim Engellendi."); } } } } }

