i need to print a pdf file, a standar print, other pdf file, other standar print, and so on. But, when i sent to the printer the sheets are mixed.
i desire:
PDF
PrintPage
PDF
PrintPage
PDF
PrintPage
but, i got (for example):
PDF
PDF
PrintPage
PrintPage
PrintPage
PDF
I'm using the following code to achive the task:
while( ... ) {
ProcessStartInfo starter = new ProcessStartInfo("path to acrobt32.exe", "/t mypdf001.pdf");
starter.CreateNoWindow = true;
starter.RedirectStandardOutput = true;
starter.UseShellExecute = false;
Process process = new Process();
process.StartInfo = starter;
process.Start();
PrintDocument pd = new PrintDocument();
pd.DocumentName = "Work";
pd.PrintPage += new PrintPageEventHandler(pd_PrintPageHandler);
pd.Print();
}
Any help will be welcome. thanks.
I cannot fully understand the issue from this small example but my guess is that the pd.Print()
method is asynchronous.
You want to make the printing synchronous. The best way would be to wrap the code in a function and call that function from the pd_PrintPageHandler
which I assume is called when the page gets printed.
A quick example to show what I mean,
function printPage(pdfFilePath)
{
ProcessStartInfo starter = new ProcessStartInfo("path to acrobt32.exe", pdfFilePath);
starter.CreateNoWindow = true;
starter.RedirectStandardOutput = true;
starter.UseShellExecute = false;
Process process = new Process();
process.StartInfo = starter;
process.Start();
PrintDocument pd = new PrintDocument();
pd.DocumentName = "Work";
pd.PrintPage += new PrintPageEventHandler(pd_PrintPageHandler);
pd.Print();
}
and in the pd_PrintPageHandler
method, call this printPage
function with the next PDF file.