0

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

Pradeep
  • 1
  • 2
  • Thanks @KJ. I have read the redmon documentation & Ghostscript implementation. But I am not able to get why is the different behavious on system restart or user signout sign in. what do you mean by "why not use the correct printer driver in the first place ? " – Pradeep Jul 04 '21 at 17:53
  • Thanks @KJ. I could use Microsoft Print to PDF and i was really using that. But this feature is disabled in windows 7 by default. So either i need to enable it on every user's system (I could do that in Powershell), But using that i did not able to figure out what is happening in the background. Moreover, Microsoft Print to PDF is not having redirection functionality. And you rightly said, there are more efficient ways for the redirection, and that is what my next step. – Pradeep Jul 05 '21 at 20:42
  • Also, as i edited my question, reading redmon output to pass to Ghostscript is taking around 4 to 5 seconds (in the case of user signout and sign in). (Normally it is only in milli seconds). – Pradeep Jul 05 '21 at 20:48

0 Answers0