Why new file for each page in C#?

Oct 19 2007 11:16 PM
In all my c++ apps, there is one file per run of the report.
I just wrote my first report in C# and it works great except for this one issue ...
every page is a new file in the Windows print queue.
The reason I know this is that I use a pdf printer for testing.
I actually have two: Jaws and Pdf995.
Jaws will append to the file name with 0,1,2 ....
Pdf995 will just overwrite the file on each page so that you get only the last page.
Our customers use pdf output to email job estimates to customers and po's to vendors
and to look at output without wasting paper. It is not acceptable to have multiple files.
In addition to that problem, there would be interleaving of different users' reports if they
chose the same printer from this app (or other c# app that was similarly coded).
This app is written with managed code (not win32) and I would like to keep it that way.
If I have to use win32, then I may as well stick with c++;
Note that our system is all browser based.
It all runs in the browser inside a company's network.
Therefore printdialog is not used nor could it be.
All current reports are run on the server in backgrould by reading a table
that pages insert a row into with printer_id and parameters.
This new app is a departure from that model, but if I could make it work, then I believe it
would make for faster development and easier maintenance.
What I cannot figure out is what/where to override to make the program produce one file.
Maybe it is not possible in managed code.
Does anyone know how to make it happen?

I have something like this:
m_mypd = new PrintDocument();
m_mypd.PrintPage += new PrintPageEventHandler(mypd_PrintPage);
m_mypd.PrintController = new  StandardPrintController();
m_mypd.PrinterSettings.PrinterName =  m_full_printer_name;
// open a reader and read first
 
while (!m_eof)
   {
   m_mypd.Print(); // one page is printed here --  why new doc on each page??
   }
   
// inside the handler ..
// headers, etc.
While (!m_eof)
   {
   if (m_currentPosition + 0.26f > m_bottomMargin) break;
   // print stuff
   m_eof = !drMain.Read();
   if (m_eof) e.HasMorePages = false;
   }
// draw vertical lines and return