vijayg 0 Newbie Poster

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

vijayg 0 Newbie Poster

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
vijayg 0 Newbie Poster

here is my code

plz tell me how i can use threads here

Process proc = new Process();

proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";

string pdfFileName = "sampletemplate.pdf";


proc.StartInfo.FileName = @"C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe";
proc.StartInfo.Arguments = @"/p /h C:\sample1.pdf";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;

proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
//proc.Kill();
}

proc.EnableRaisingEvents = true;
// AcroRd32.exe
proc.CloseMainWindow();
proc.Close();

vijayg 0 Newbie Poster

i am not familiar with threading so can u help me ..
how 2 work with it..

vijayg 0 Newbie Poster

u mean to say like this??
if (!proc.HasExited)
{
proc.Refresh();
Thread.Sleep(2000);
}

vijayg 0 Newbie Poster

proc.WaitForExit(10000);
if we do not use waitforexit and print some big pdf it will give error, as it takes some time and process will be exited

vijayg 0 Newbie Poster

Thanks for quick reply

plz see below code that i am using to print

using System.Diagnostics;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
Process proc = new Process();

proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";

string pdfFileName = "sampletemplate.pdf";


proc.StartInfo.FileName = @"C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe";
proc.StartInfo.Arguments = @"/p /h C:\sample1.pdf";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;

proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
//proc.Kill();
}

proc.EnableRaisingEvents = true;
// AcroRd32.exe
proc.CloseMainWindow();
proc.Close();

plz explain ur point...

vijayg 0 Newbie Poster

u can print pdf files using this code .................

using System.Diagnostics;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
Process proc = new Process();


proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";


string pdfFileName = "sampletemplate.pdf";



proc.StartInfo.FileName = @"C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe";
proc.StartInfo.Arguments = @"/p /h C:\sample1.pdf";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;


proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
//proc.Kill();
}


proc.EnableRaisingEvents = true;
//  AcroRd32.exe
proc.CloseMainWindow();
proc.Close();

:)

vijayg 0 Newbie Poster

can anyone help me to print pdf files in c#
If we use process we have to wait for some minutes.so is there any way print it directly without thread.sleep and waitforexit