-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: thinkindotnet
Message 1 in Discussion
Hi folks, I have used the following code for printing option thro' windows forms.
If the document I print is just a text file, then there is no issue, it is printing it
very fine. When the document is PDF, it is not printing it instead it is printing like
the one shown here /Dest (G1046966) /Type /Annot /Subtype /Link /Border [000] ..,
what could be the reason. Is there any printer setting.. ? -One reason could be the
POSTSCRIPT, which is the base of the PDF document. -Here the StreamReader class,
which has the option of setting the Encoding.., do we need to set any encoding..., if
so what to set...? Thanks, Suki
****************************************************** using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO; namespace PDFPrinter
{
/// <summary>
/// Summary description for PrintController.
/// </summary>
public class PrintController
{
private Font printFont;
private StreamReader streamToPrint;
static string filePath; public PrintController()
{
}
// 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) ;
// Iterate over the file, printing each line.
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;
}
// Print the file.
public void Printing()
{
try
{
streamToPrint = new StreamReader (filePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.Close() ;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void PrintThis()
{
filePath = "C:\\CheckPrinting.txt"; Printing();
}
}
}
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]