Skip to content

Instantly share code, notes, and snippets.

@alvin2ye
Created August 31, 2017 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvin2ye/a114e62e0e175c2a57075bf56f8c9cbd to your computer and use it in GitHub Desktop.
Save alvin2ye/a114e62e0e175c2a57075bf56f8c9cbd to your computer and use it in GitHub Desktop.
PrintDocument p = new PrintDocument();
if (options.PrinterName.Length > 0)
{
p.PrinterSettings.PrinterName = options.PrinterName;
}
p.PrintPage += delegate(object sender1, PrintPageEventArgs e1)
{
Font font = new Font(options.FontName, options.FontSize);
SolidBrush solidBrush = new SolidBrush(Color.Black);
string line;
int lineno = 0;
System.IO.StreamReader file = new System.IO.StreamReader(options.PrintFile);
while ((line = file.ReadLine()) != null)
{
e1.Graphics.DrawString(line, font, solidBrush, new RectangleF(startX, startY + lineHeight * lineno, lineWidth, lineHeight));
lineno++;
}
file.Close();
};
p.Print();
p.Dispose();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment