Skip to main content
Participant
August 2, 2007
Question

VB.Net Printing of PDFs

  • August 2, 2007
  • 20 replies
  • 40772 views
I am trying to print a pdf document to a specific printer from VB.Net app. I would like this to be a silent process i.e. no print dialog and no Acrobat Reader popping up.

This solution must only use reader as it needs to work without licensing issues.

Anyone got any ideas?

I have managed to do it using the command line options but a reader window pops up and wont go away.
This topic has been closed for replies.

20 replies

Participant
June 26, 2008
I have to say this is pretty bull that there is no way to stop adobe from popping up into the focus.

I run a server program for our business which does batch printing via ole automation in vb6(among other things) and the server can print up to 1000 pdfs a day.

Now before our company reviewed and approved adobe 8 for use I was stuck using version 6 and had to deal with the msgbox "this is a newer version of adobe, click ok to continue" for every...single...document...because Adobe does not save your settings outside of your current session with adobe(ie checking the box in the pop up that says "check here to never display this again" does nothing).

Now I have to deal with Adobe popping up every...single...pdf... I could live with that if it did not always force itself to be the focus and interrupt what else I may be working on. I am one of the most patient people but this has me in a near rage.
Participant
March 13, 2008
No method that waits for a defined period before killing the Reader process will work correctly for all PDFs and printers.

It's much better to know for sure that print spooling is done before closing Reader.

See pdfp8 here for a utility (with C source) that does this:

http://www.esnips.com/web/PDFTools
Participant
March 10, 2008
I have got arround the problem by writing some code to change the default printer to the required printer and source tray etc then print using /t on the command line - see below. I hope this helps anyone trying to do this.

Dim objStartInfo As New ProcessStartInfo
objProcess = New System.Diagnostics.Process

' set start info properties
With objStartInfo
'.CreateNoWindow = True
.FileName = AcrobateViewerPath
.Arguments = "/t """ & Filename & """"
.UseShellExecute = False
'.WindowStyle = ProcessWindowStyle.Hidden
.ErrorDialog = True
.RedirectStandardError = True
End With

' start process
Try
objProcess = Process.Start(objStartInfo)
Catch ex As Exception
MsgBox("Error printing")
End Try

'wait for process to print
System.Threading.Thread.Sleep(10000)

'kill processes called AcroRd32
Dim myprocesses As Process() = System.Diagnostics.Process.GetProcessesByName("AcroRd32")
For Each myproces As Process In myprocesses
myproces.Kill()
Next
Participant
March 10, 2008
I work with production printing customers and some would like to batch print PDF files; and they would like to do that in the background on their PC. "Silent" printing would be nice because they don't want a print dialog for each and every PDF being printed.
Participant
January 18, 2008
Try the following code. It is working for us..
Const SEE_MASK_NOCLOSEPROCESS = &H40
Const SEE_MASK_FLAG_NO_UI = &H400
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type

Declare Function ShellExecuteEx Lib "shell32.dll"Alias "ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long
Declare Function TerminateProcess Lib "kernel32"Alias "TerminateProcess" (Byval hProcess As Long, Byval uExitCode As Long) As Long

Function PrintPDF() as Boolean
On Error Goto PrintDocErrorHandle

PrintDoc = False

Dim SEI As SHELLEXECUTEINFO
SEI.cbSize = Len(SEI)
SEI.fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_FLAG_NO_UI
SEI.lpVerb = "Print"
' SEI.lpVerb = "Open"
SEI.lpFile = strFname
SEI.lpDirectory = s.GetEnvironmentString( "Directory" , True ) & strExtractPath
SEI.nShow = 1
SEI.hInstApp = 0
SEI.lpIDList = 0
Call ShellExecuteEx(SEI)
Sleep(3) ' file was being deleted before it could be printed.
Call TerminateProcess(SEI.hProcess, 0)
'Print "Return Code = " & Cstr( SEI.hInstApp )
If SEI.hInstApp < 32 Then
errMsg = errMsg & Chr(13) & "Error printing document: " & strFname & ". Document Subject: " & doc.subject(0) & ". Document: " & doc.UniversalID & ". Print return code: " & Cstr( SEI.hInstApp)
Else
successMsg = successMsg & Chr(13) & "Successfully printed document: " & strFname & " from " & doc.subject(0)
End If

PrintDoc = True
exitFunctionCode:
Exit Function

PrintDocErrorHandle:
flag = 1300
errMsg = errMsg & Chr(13) & "Error printing document: " & strFname & ". " & Error() & ". Document subject: " & doc.subject(0) & ". Document: " & doc.UniversalID
Resume exitFunctionCode
Participating Frequently
January 9, 2008
What is the workflow that you envision where you need to "silent print"?

Leonard
Participant
January 9, 2008
" Reader is designed to "pop up" to ensure that no one uses Acrobat/Reader as "malware" to start doing unrequested silent printing on the user's computer. "

So, then how can one do
requested
silent printing???
Participant
August 2, 2007
I won't comment about why Adobe does this, but you might be able to work around the issue using the techniques I employed in pdfp / pdfp8 here:

http://www.esnips.com/web/PDFTools
Participant
August 2, 2007
OK nevermind.

Anyone know a non adobe component that is either free or cheap that could do this?
Participating Frequently
August 2, 2007
Reader is designed to "pop up" to ensure that no one uses Acrobat/Reader as "malware" to start doing unrequested silent printing on the user's computer.

You can certainly use Windows APIs to "hide" it after the fact, but it will first pop up.