Hi am printing pdf file with following code,But it does not print pdf in poper format.. it prints in stream ...

private void button1_Click(object sender, EventArgs e)
{
try
{



streamToPrint = new StreamReader
("C:\\MyFile.doc");


try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler
(this.pd_PrintPage);


pd.Print();



}
finally
{
streamToPrint.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}


}
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;
}


Print:
%PDF-1 .4
%
1 0 obj
/Title <> /Author <> /Keywords <> /Subject <> /Creator <504446344E455420332E332E332E302028687474703A2F2F7777772E6F32736F6C 2E636F6D2F29> /Producer <504446344E455420332E332E332E302028687474703A2F2F7777772E6F32736F6C 2E636F6D2F29> /CreationDate <443A323030383039323531 31 303433332B303527333027> /Mod Date <443A323030383039323531 31 303433332B303527333027> /CreationDate <443A323030383039323531 31 303433332B303527333027> /Mod Date <443A323030383039323531 31 303433332B303527333027>
>>
endobj
2 0 obj
/Type /Font /Subtype /Typel /BaseFont /Helvetica /Encoding /WinAnsiEncoding
/Name /Font_CDE9AA741 85247298846EF1 FF08F2559
>>
endobj
3 0 obj
/Type /ExtGState /CA 1 Ica 1
>>
endobj
4 0 obj
/Type /Font /Subtype /Typel /BaseFont /Helvetica /Encoding /WinAnsiEncoding

Edited 3 Years Ago by happygeek: fixed formatting

how i can print in proper format rather than
below sample.....
Print:

%PDF-1 .4
%
1 0 obj
/Title <> /Author <> /Keywords <> /Subject <> /Creator <504446344E455420332E332E332E302028687474703A2F2F7777772E6F32736F6C 2E636F6D2F29> /Producer <504446344E455420332E332E332E302028687474703A2F2F7777772E6F32736F6C 2E636F6D2F29> /CreationDate <443A323030383039323531 31 303433332B303527333027> /Mod Date <443A323030383039323531 31 303433332B303527333027> /CreationDate <443A323030383039323531 31 303433332B303527333027> /Mod Date <443A323030383039323531 31 303433332B303527333027>
>>
endobj
2 0 obj
/Type /Font /Subtype /Typel /BaseFont /Helvetica /Encoding /WinAnsiEncoding
/Name /Font_CDE9AA741 85247298846EF1 FF08F2559
>>
endobj
3 0 obj
/Type /ExtGState /CA 1 Ica 1
>>
endobj
4 0 obj
/Type /Font /Subtype /Typel /BaseFont /Helvetica /Encoding /WinAnsiEncoding

have a look in the rest of this forum theres a bunch of threads about printing PDFs and probably the simplest is to use adobe to do it for you.

A driver would need to know its a PDF file to print, not just get the text of the PDF.

This article has been dead for over six months. Start a new discussion instead.