Print Multiple PDF Files

Gismo

Registered User.
Local time
Today, 12:18
Joined
Jun 12, 2017
Messages
1,298
Hi all,
Please could you assist?
I have about 60 different PDF Files on the server.
I have created a Table with hyper links to all of them.
Depending on my query result, I need to print some of the PDF Files in a batch and in a specific sequence.
Who do I do this?
Do I use a report with the PDF hyperlinks as sub reports or is there an different method I should approach?
 
Hi. You could try using the ShellExecute API.
 
Recently found code for this in response to another thread:
Code:
Option Compare Database
Option Explicit
 
Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
   (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
 
Sub Test_Printpdf()
  Dim fn$
  fn = "C:\Users\June\MyStuff\HoldMail.pdf"
  PrintPDf fn
End Sub
 
Sub PrintPDF(fn$)
  Dim pdfEXE$, q$
  pdfEXE = ExePath(fn)
  If pdfEXE = "" Then
    MsgBox "No path found to pdf's associated EXE.", vbCritical, "Macro Ending"
    Exit Sub
  End If 
  q = """"
  'http://help.adobe.com/livedocs/acrobat_sdk/10/Acrobat10_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat10_SDK_HTMLHelp&file=DevFAQ_UnderstandingSDK.22.31.html
  '/s/o/h/p/t
  Shell q & pdfEXE & q & " /s /o /h /t " & q & fn & q, vbHide
End Sub
 
Function ExePath(lpFile As String) As String
   Dim lpDirectory As String, sExePath As String, rc As Long
   lpDirectory = "\"
   sExePath = Space(255)
   rc = FindExecutable(lpFile, lpDirectory, sExePath)
   sExePath = Left$(sExePath, InStr(sExePath, Chr$(0)) - 1)
  ExePath = sExePath
End Function
 
Last edited:
This code is for one specific PDF file, not so?
I need to select a few PDF files to print in succession.
 
Select them how? File path is in table text field? Adapt code. Open a recordset, loop through recordset, print pdf. Might need Timer code to allow enough time for the pdf to be queued to printer before continuing loop:
Code:
        Dim Start As Double
        Start = Timer
        While Timer < Start + 3
          DoEvents
        Wend
 
I have a folder with numerous PDF files, If I need to print them all, I can not use
Code:
C:\Users\June\MyStuff\HoldMail.pdf

Lets say I want to print all PDF files in the same folder.
 
Thank you,
I looked at the sample but I have no idea how to do this.
I copied the code and tried to change but I am not very familiar with modules
 
You said you have hyperlinks in table. Why would you need to iterate through folder instead of a recordset?

However, if the field is Hyperlink data type, it will not work as is. Hyperlink is composed of 3 parts separated by # character. Code would have to extract the file path from the hyperlink string. So is this a Hyperlink field or a Text field?

Do you want to iterate a filtered recordset or a folder?
 
I use this code to combine multiple PDF's into a single file and into a folder on the desktop called Forlift Cert.

Code:
On Error GoTo Form_Err

  DoCmd.OutputTo acOutputReport, "rptForkliftCert", _
  acFormatPDF, "C:\Users\SomeUser\Desktop\Forlift Cert\Current Forklift Certs.pdf", True

Form_Exit:
   Exit Sub

Form_Err:
    MsgBox Err.Description
    Resume Form_Exit
 
Blaster, that code does not combine PDFs, it simply outputs a report to PDF. And it does not print PDF.
 
Hi June, multiple records going into one file name this creates multiple pages within the same document.
I will try an incude a screen shot.

This could be more a function of the report than the code.
 
Last edited:
That is correct. Combining PDF files with VBA requires manipulating Acrobat objects and Adobe Acrobat (not the Reader) must be installed. Although there may be some third-party apps that can do it.
 
Last edited:
You said you have hyperlinks in table. Why would you need to iterate through folder instead of a recordset?

However, if the field is Hyperlink data type, it will not work as is. Hyperlink is composed of 3 parts separated by # character. Code would have to extract the file path from the hyperlink string. So is this a Hyperlink field or a Text field?

Do you want to iterate a filtered recordset or a folder?

it will be a folder
 
Simple code to loop through folder, call sub to print PDF files. Where will folder be located?
Code:
Sub GetPDF()
    Dim strFile As String
    strFile = Dir("C:\your folder path\*.pdf")
    Do While strFile <> ""
        PrintPDF strFile
        strFile = Dir
    Loop
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom