Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print PDF as another user? #127

Open
rconstantine opened this issue Oct 26, 2020 · 1 comment
Open

Print PDF as another user? #127

rconstantine opened this issue Oct 26, 2020 · 1 comment

Comments

@rconstantine
Copy link

Hello, I'm trying to print a PDF silently from an ExpressJS server application using a command similar to this structure per documentation for Adobe: AcroRd32.exe /N /T PdfFile PrinterName [ PrinterDriver [ PrinterPort ] ]

I only need up through the PrinterName. I have this hardcoded in my app, but it only works on my dev machine, which is run from the WebStorm IDE using "yarn run dev" which calls this: "dev": "cross-env NODE_OPTIONS=--max_old_space_size=10240 NODE_ENV=development nodemon -w src --exec "babel-node src --presets env" && echo "dev called"",

Here is my command in my ExpressJS app: ps.addCommand(& "C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\AcroRd32.exe" /N /T "C:\\SutterNow_Reports\\antibiotics_active^CVLB^2020-10-22T0657.pdf" "Bullzip PDF Printer")

Calling ps.invoke() works on my DEV machine, like I said.

I will be replacing the PdfFile and PrinterName dynamically using choices from my client app. Ignore, for now, that I'm sending a PDF to a PDF printer, thus making another PDF. I won't be doing that in QA or PROD. I have the printer queue paused so I can see the file land and delete it.

Anyway, when I compile and move to my QA server, I see that Acrobat has no user associated with it in Task Manager, whereas my username is the one it runs under in DEV. So I'm thinking I need to make sure the above runs as SOMEONE. I have a service account I can use.

I tried just adding this to the end of my command, above, but it obviously didn't work: -Credential (New-Object System.Management.Automation.PSCredential + username + ,(ConvertTo-SecureString + password + -AsPlainText -Force))

I don't think I can run a ps1 file or something. Or at least, I don't know how to pass parameters in from my app to a ps1 file. So what am I doing wrong? I'm obviously not a powershell user at all, and there's so much documentation that doesn't seem to apply to using it in a server app. There's a link in another issue pointing to hash tables and stuff that was just confusing, partly because the author was using a ps1 file, which I don't think I can use in my case. Perhaps I'm wrong about that.

Any pointers?

@rconstantine
Copy link
Author

Looks like formatting didn't all stick, but imagine the line with username and password as being properly escaped and concatenated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant