I create prn code from pdfs and send them to printers in a C# code to automatize printing jobs. To do that, I use ghost script with following parameters.
gswin32c -dNOPAUSE -dBATCH -sDEVICE=laserjet -sOutputFile="c:/temp/out.prn" "NumberedPages.pdf"
This commandline arguments generates a prn file named out.prn. When I send this file to the printer with following C# code, it prints the pdf file successfully.
public static bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, Int32 dwCount)
{
uint returnedValue = 0;
Int32 dwError = 0, dwWritten = 0;
IntPtr hPrinter = new IntPtr(0);
DOCINFOA di = new DOCINFOA();
bool bSuccess = false; // Assume failure unless you specifically succeed.
di.pDocName = "My C#.NET RAW Document";
di.pDataType = "RAW";
// Open the printer.
if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
{
// Start a document.
returnedValue = StartDocPrinter(hPrinter, 1, di);
if (0 != returnedValue)
{
// Start a page.
if (StartPagePrinter(hPrinter))
{
// Write your bytes.
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
}
// If you did not succeed, GetLastError may give more information
// about why not.
if (bSuccess == false)
{
dwError = Marshal.GetLastWin32Error();
}
return bSuccess;
}
(https://stackoverflow.com/a/29564132/3079364)
I also want to monitor the print jobs if they are successfully printed by the printer or not. But the prn file which is generated by ghost script does not reflects the correct number of pages. See below
Captured from CZ Print job tracker
When I print this document using Word or Adobe, CZ Print job tracker shows the correct number of pages.
Is there any parameter that I can add to ghost script command to correct this information ?