0

I'm trying to print a .pdf file using a shell. The printout comes from the default printer, but I would like to do it in the mode without opening Adobe Reader, I would like it to be invisible to the user. I tried to use the "SW_HIDE" variable but at this point the printout does not come out at all. I will be grateful for your help.

My code:

Const SW_SHOWNORMAL = 1
Const SW_HIDE = 0
Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long


Private Sub Command1_Click()
 Dim PrintIt As Long
 PrintIt = ShellExecute(Me.hwnd, "print", "C:\Test.pdf", "", "", SW_SHOWNORMAL)
'Pdf1.src = "C:\test.pdf"
'Pdf1.printAll
End Sub```
Amessihel
  • 5,891
  • 3
  • 16
  • 40
mateo98
  • 21
  • 3
  • 2
    https://stackoverflow.com/questions/61933672/printing-file-using-c-sharp-at-server?noredirect=1&lq=1#comment109541970_61933672 – GSerg Aug 13 '21 at 11:00

1 Answers1

0

If I understand the question correctly, you want to use a headless PDF printer so the user does not know which application is doing the printing.

Looks like Adobe does not allow this and doing this could violate their license: https://community.adobe.com/t5/acrobat-sdk/how-to-print-a-pdf-programmatically-without-the-adobe-reader-window/m-p/4343967

Most important – have you read the Acrobat Reader EULA to ensure that your use is compliant? Many batch and headless operations are not compliant with the EULA.

If you do not have to use Adobe Reader, there are a number of other PDF printer applications that allow silent installation and headless printing.

eglease
  • 2,445
  • 11
  • 18
  • 28
  • Google Chrome has PDF-print function. This function can be automated. – Daemon-5 Aug 31 '21 at 04:37
  • True, and looks like there is a headless Chrome as well. The problem is that Chrome either needs to be already installed or you need to install it with the VB applications. It is much easier to package a small PDF printing service with the application. Not sure about licensing. – eglease Aug 31 '21 at 14:21