Skip to content

C#-APP How to get byte/stream of printed file

Wahyu Hidayat

Asked Dec 1, 2008, 8:16 PM EST1 answer
Share
LinkedInX
I write the code to get stream/bytes of printed file as follow:

private PrintSystemJobInfo GetInfo()
{
LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue q = LocalPrintServer.GetDefaultPrintQueue();
q.Refresh();
foreach (PrintSystemJobInfo pj in q.GetPrintJobInfoCollection())
{
return pj;
}
return null;
}
PrintSystemJobInfo pj = GetInfo();
int len = pj.JobStream.Length;

I use Windows XP Sp2
When executing len = pj.JobStream.Length an error occur "Object reference not set to an instance of an object."

Is JobStream works in XP? Because I read that it works on vista only. Is there any other solution?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    +1
    Because of this loop

    foreach (PrintSystemJobInfo pj in q.GetPrintJobInfoCollection())
    {
    return pj;
    }
    return null;


    the return null; return a null pj
    +1