Hi Hadi,
Thanks for your patience and cooperation. In referenced thread, we have implemented
PrintController Class to print text file. Please refer code snippet as following. Hopefully it would help you to meet your requirements.
private StreamReader streamToPrint;
private Font printFont;
public void CreatePDFNET_11409(string issueID, string fileName)
{
streamToPrint = new StreamReader(string.Format("{0}{1}.txt", InputPath, issueID));
try
{
printFont = new Font(“Arial”, 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
PrintController pc = new Aspose.Pdf.PrintController();
pc.FileName = fileName;
pd.PrintController = pc;
pd.Print();
}
finally
{
streamToPrint.Close();
}
}
// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /printFont.GetHeight(ev.Graphics);
// Print each line of the file.
while (count < linesPerPage &&
((line = streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count *printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black,leftMargin, yPos, new StringFormat());
count++;
}
// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
Note: Please check printer should be installed on your PC.
Best Regards,