pdf redirection to Windows Printer using Ghostscript

622 views Asked by At

I am working on a Virtual PDF Printer (using redmon & Ghostscript) which have two responsibilities:

  1. Create PDF (using pdfwrite)
  2. Redirect created PDF to specified printer (using mswinpr2)

Everything works fine except in one peculiar case: When User signout & signin on Windows 10. In this case, the Ghostscript call to redirect to the specified printer gets hanged and stuck. It doesn't comes out unless system restart. I have more dig up and found the issue that whenever print is happening, my program starts with System user (in the case when user signout and signin). And that is why the redirection is not happening. But there is one more issue with this case is reading redmon output to pass to Ghostscript is taking around 4 to 5 seconds. (Normally it is only in milli seconds).

I am using Ghostcript 9.54 (latest) and using the API mentioned in the below GitHub repo: https://github.com/mephraim/ghostscriptsharp

  1. For PDF Write:

    String[] ghostScriptArguments = { "-dBATCH", "-dNOPAUSE", "-dSAFER", "-sDEVICE=pdfwrite", "-dAutoRotatePages=/None", String.Format("-sOutputFile={0}", outputFilename), standardInputFilename, "-c "<</Orientation 0>> setpagedevice"" ,@"[/Creator(ZBPrinter 2.1.5 (PSCRIPT5)) /DOCINFO pdfmark", "-f"}; GhostScript.CallAPI(ghostScriptArguments);

  2. For PDF redirect to printer:

    String[] ghostScriptArguments = {"-empty", "-dPrinted", "-dBATCH", "-dNOPAUSE", "-dNOSAFER", "-dNOINTERPOLATE", "-dNOCIE","-dNumCopies=1", "-sDEVICE=mswinpr2", String.Format("-sOutputFile=%printer%{0}", printerName),"-f", pdfFilename}; GhostScript.CallAPI(ghostScriptArguments);

Some more observations on User Signout / Signin on Windows 10:

  1. On User Sign out & sign in, and then if print to my virtual printer, I have taken the Redmon port logs and found the below differences: a) REDMON_SESSIONID value will be 1 or incremented value, while on system restart the session id value is 0 (ie Admin access) b) The APPDATA directory is pointed to C:\Windows\system32\config\systemprofile\AppData\Roaming whereas it was C:\Users<Username>\AppData\Roaming on System restart. c) The USERPROFILE value is pointed to C:\Windows\system32\config\systemprofile.

Please help me out in this to find why PDF redirection to specific printer is not working on User signout / sign in on Windows 10.

Thanks, Pradeep Gupta

0

There are 0 answers