I currently use the code:
private void Print()
{
string PrinterName =
PrintLocationDataHandler.getPrinterName("Reports");
PrintDocument PD = new PrintDocument
();
PD.PrinterSettings.PrinterName = PrinterName;
PD.PrintPage += new
PrintPageEventHandler(PD_PrintPage);
PD.Print();
}
void PD_PrintPage(object sender, PrintPageEventArgs e)
{
String textToPrint = richTextBox1.Text;
Font printFont = new Font("Courier New", 12, FontStyle.Bold);
e.Graphics.DrawString(textToPrint, printFont, Brushes.Black, 0, 0);
}
private void button1_Click(object sender, EventArgs e)
{
Print();
}
The problem i am running into is that when it hits a new page, it just stops. I assumed the printer would automatically know when to start a new page, but it doesnt. I am printing directly from a rich text box.
Loading
Master BillaPosted Sep 11, 2009, 12:27 PM
try this with code,
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace Test
{
public class Print
{
PrintDocument myPrintDocument = new PrintDocument();
public void ShowPrintDialog()
{
PrintDialog myDialog = new PrintDialog();
myDialog.Document = myPrintDocument;
if(myDialog.ShowDialog() == DialogResult.OK)
Print();
}
protected override void OnPrintPage(PrintPageEventArgs e)
{
Rectangle PageBounds = new Rectangle(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height);
Pen LinePen = new Pen(Color.Black);
e.Graphics.DrawLine(LinePen, PageBounds.Left, PageBounds.Top, PageBounds.Left + pageBounds.Width, PageBounds.Top);
e.HasMorePages = false;
}
}
}
thank you
Niradhip ChakrabortyPosted Sep 12, 2009, 5:02 AM
Here is one sample code using PrintDocument
//===================================================================
Private Sub frmThankYou_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PrintDocument1.PrinterSettings.Copies = 1
PrintDocument1.Print()
PrintDocument1 = Nothing
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim strPaymentReceipt As String = "Payment Receipt"
Dim strCompanyname As String = "my Address"
Dim strStreetAddress As String = "My street"
Dim strAddress As String = "Brooklyn , NY 11224 "
Dim strPhone As String = "Tel: (888)940 -8881"
e.Graphics.DrawString(strPaymentReceipt, printFont, Brushes.Blue, 100, 0)
e.Graphics.DrawString(strCompanyname, printFont, Brushes.Blue, 100, 15)
e.Graphics.DrawString(strStreetAddress, printFont, Brushes.Blue, 100, 30)
e.Graphics.DrawString(strAddress, printFont, Brushes.Blue, 100, 45)
e.Graphics.DrawString(strPhone, printFont, Brushes.Blue, 100, 60)
End Sub