VB.Net Printing of PDFs
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You can certainly use Windows APIs to "hide" it after the fact, but it will first pop up.
Copy link to clipboard
Copied
Anyone know a non adobe component that is either free or cheap that could do this?
Copy link to clipboard
Copied
http://www.esnips.com/web/PDFTools
Copy link to clipboard
Copied
So, then how can one do
requested
silent printing???
Copy link to clipboard
Copied
Leonard
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Well, there's your problem. Acrobat is not designed for server use, and it's actually expressly forbid in the EULA (Section 2.3, Server Use). Using it in a server-based automation fashion is a violation of the EULA, and since you've just publicly posted on Adobe forums that you're using it in that way it would probably be a good idea to remove it from your server before you get a call from Adobe Legal (believe me, they do follow-up on license violations).
The OLE automation is designed to automate desktop installs of Acrobat. It is, per the EULA and documentation, required that each end-user have a licensed copy of Acrobat on their machine and that the automation software be installed locally on their machine as well. There can be no situation where multiple users are submitting requests to a single copy of Acrobat in an automated fashion.
The reason its not working the way you expect it to is because it was expressly designed NOT to work in a server environment. That's what the LiveCycle products are for. Using Acrobat as part of any server-based workflow is illegal, so Adobe certainly don't develop it to be server-friendly.
Copy link to clipboard
Copied
Either way if we misread what means to be a stand alone application and not I apologize. We will gladly switch to an alternative since this is small piece of it.
Copy link to clipboard
Copied
I apologize if the language I used out of habit is confusing.
Copy link to clipboard
Copied
Your best bet, since you have a full version of Acrobat, would be to create a silent print plug-in in C/C++ and then call that plug-in from your VB application. That way you can assure it is a silent, dialog-less print (and quite frankly, a simple silent print plug-in that doesn't require any advanced configuration options will not take long to build at all for an experienced developer).
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Set it as the default printer (can do this in the code if you want)
Set the settings in the PDFCreator Printer options in the Auto-save section to not have pop-ups and where to save the document.
If you want to get fancy, you can call the word, excel, or whatever with a minimized window to get NO windows popping up.
Let it fly:
Imports System
Imports System.Diagnostics
Imports System.IO
Module Module1
Const pdfTempFolder As String = "c:\tempPDF"
Const pdfResultsFolder As String = "c:\tempPDF\"
Dim DocumentName As String
' ------------------------------------------------------------
Dim di As New IO.DirectoryInfo("c:\tempPDF")
Dim aryFi As IO.FileInfo() = di.GetFiles("*.doc")
Dim fi As IO.FileInfo
Sub Main()
For Each fi In aryFi
Console.WriteLine("File Full Name: {0}", fi.FullName)
DocumentName = fi.FullName
Print(DocumentName)
Next
End Sub
Sub Print(ByVal DocumentName)
Dim proc As New Process
Console.WriteLine("DocumentName Sent to Process Start is: " + DocumentName)
proc.StartInfo.FileName = DocumentName
proc.StartInfo.Verb = "Print"
proc.StartInfo.CreateNoWindow = True
proc.Start()
End Sub
End Module
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
VB.NET
Arguments = "/t """ & Filename & """"
by
C#
Arguments = "/t " + path_file + " " + path_printer + ""
Copy link to clipboard
Copied
i wrote an article how to open and show and silent print pdfs in Windows and Mac OSX with examples (using native commands):
http://www.onyrix.com/2012/04/adobe-air-pdf-silent-print-with-acrobat-reader/
bye
d
even if is for Adobe Air you can you native commands examples for any other programming language

