 |
tsang_kc Level: Trainee
 Registered: 20-03-2005 Posts: 1
|
How can print PDF file automatically?
Hi,
I want to setup a program, it can print PDF file to a printer in background automatically?
Anybody know what should I do? I am a VB beginner.
Regards,
KC
|
|
|
20-03-2005 at 03:08 PM |
|
|
Ramya Level: Sage
 Registered: 08-04-2005 Posts: 59
|
Re: How can print PDF file automatically?
Hai
I am not very clear about it.Yet i will give u a hint.When u install PDF printer in ur system and if u give as print it will automatically goes for pdf
|
|
15-06-2005 at 07:28 AM |
|
|
skuller Level: Trainee
 Registered: 25-05-2005 Posts: 3
|
Re: How can print PDF file automatically?
'IN this I am sending the path to the pdf file in my variable strFilePath. then will run through the code
Public Function Print_pdf_document(strFilePath As String)
On Error GoTo errHandler
Dim Error282Count As Integer '' Count of "Can't open DDE channel" errors
Dim AcroDDEFailed As Boolean '' Set to true if a DDE connection cannot be established
Dim sPDFPath As String '' Path to a PDF file
Dim sCmd As String '' DDE command
Dim lStatus As Long
Dim n As Integer
Const Max282Errors = 6
Dim sAcroPath As String ' Path to acrobat, determined by FindExecutable
Dim bCloseAcrobat As Boolean ' If we open acrobat, we will close it when we are done
Dim PDFArray As Variant
Error282Count = Max282Errors ' checks to see if acrobat is running
AcroDDEFailed = False ' ErrHandler will set to true if Acro is not running
txtAcrobatDDE.LinkMode = 0 ' Close any current DDE Link
txtAcrobatDDE.LinkTopic = "acroview|control" ' Acrobat's DDE Application|Topic
txtAcrobatDDE.LinkMode = 2 ' Try to establish 'Manual' DDE Link. This will fail
' if Acrobat is not ready or running
'This will determine what the default printer is on the system
Set objPrinter = GetDefaultPrinter()
'This will set the default printer according to the settings in TNClerk
Call SetNewDefaultPrinter
'Obtain the current settings the printer has
PreviousSettings = Printer.PaperSize
'Check to see if need to print legal or letter size
If Me.optLegal.Value = True Then
If Printer.PaperSize <> 5 Then
Call SetPaperSize(5)
End If
ElseIf Me.optLetter.Value = True Then
If Printer.PaperSize <> 1 Then
Call SetPaperSize(1)
End If
End If
ReDim PDFArray(0 To 0)
PDFArray(0) = strFilePath
If AcroDDEFailed = True Then
' grab the first pdf path. We assume this file exists
sPDFPath = PDFArray(0)
'' Use the FindExecutable API function to grab the path to our PDF handler.
sAcroPath = String(128, 32)
lStatus = FindExecutable(sPDFPath, vbNullString, sAcroPath)
If lStatus <= 32 Then
MsgBox "Acrobat could not be found on this computer. Printing cancelled", vbCritical, "Problem"
Call ReturnDefaultPrinter
Exit Function
End If
' Launch the PDF handler
lStatus = Shell(sAcroPath, vbHide)
If (lStatus >= 0) And (lStatus <= 32) Then
MsgBox "An error occured launching Acrobat. Printing cancelled", vbCritical, "Problem"
Call ReturnDefaultPrinter
Exit Function
End If
'Try to close Acrobat when we are done
bCloseAcrobat = True
End If
PauseFor 2 '' Lets take a break here to let Acrobat finish loading
Error282Count = 0 '' This time, we will allow all acceptable tries, as
AcroDDEFailed = False '' Acrobat is running, but may be busy loading its modules
txtAcrobatDDE.LinkMode = 0
txtAcrobatDDE.LinkTopic = "acroview|control"
txtAcrobatDDE.LinkTimeout = 2500 ' 3 minute timeout delay
txtAcrobatDDE.LinkMode = 2
If AcroDDEFailed = True Then
MsgBox "An error occured connecting to Acrobat. Printing cancelled", vbCritical, "Problem"
Call ReturnDefaultPrinter
Exit Function
End If
'' Send the PDF's to the printer.
For n = 0 To UBound(PDFArray)
'' We need to put the long filenames in quotes. Again, we assume these file exist
sPDFPath = PDFArray(n)
sCmd = "[FilePrintSilent(" & Chr(34) & sPDFPath & Chr(34) & ")]"
txtAcrobatDDE.LinkExecute sCmd
Next
If bCloseAcrobat = True Then
'' [AppExit()] causes memory errors with v6.0 and 6.1, so avoid closing these versions
If InStr(sAcroPath, "6.0") = 0 Then
sCmd = "[AppExit()]"
txtAcrobatDDE.LinkExecute sCmd
End If
End If
'' Close the DDE Connection
txtAcrobatDDE.LinkMode = 0
Call ReturnDefaultPrinter
Exit Function
errHandler:
If err.Number = 282 Then '' Can't open DDE channel
'' This error may happen because Acro is not fully loaded.
'' Give it Max282Errors attempts before returning AcroDDEFailed = True
Error282Count = Error282Count + 1
If Error282Count <= Max282Errors Then
PauseFor 3
Resume
Else
AcroDDEFailed = True
Resume Next
End If
End If
MsgBox "Error in PrintPDFs sub of " & Me.Name & " form. Error# " & err.Number & " " & err.Description & "."
End Function
|
|
21-06-2005 at 04:53 PM |
|
|
elizas Level: Trainee
 Registered: 13-04-2010 Posts: 3
|
Re: How can print PDF file automatically?
Following is the sample code in [VB.NET]
'--Declaration
Public Declare Auto Function FindExecutable Lib "shell32.dll" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Int32
'--
Dim intRetval As Integer = FindExecutable(PDF FILE FULL PATH NAME, "", "")
If intRetval < = 32
MessageBox.Show("The Adobe Reader, which is required to view this file, may not be correctly installed.", "Adobe Reader Not found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End if
http://www.mindfiresolutions.com/FindExecutable-API-569.php
|
|
07-05-2010 at 08:44 AM |
|
|
ziumus Level: Trainee
 Registered: 08-03-2012 Posts: 1
|
Re: How can print PDF file automatically?
You can try this:
Print a PDF file with dialog:
AcroRd32.exe /P PdfFile
Print a PDF file silently:
AcroRd32.exe /N /T PdfFile PrinterName [ PrinterDriver [ PrinterPort ]
If doesn't work for you can try some other tools, I am using CLPRINT tool, works great, if you want more infrmations please visit http://www.commandlinepdf.com/
|
|
08-03-2012 at 05:37 PM |
|
|
|
|
 |
 |