Link to home
Start Free TrialLog in
Avatar of wellesleydpw
wellesleydpw

asked on

Print first page of each file - PDF

I have a table with the full paths of several files (that happen to be PDFs).

I have this code that will print all the files but I would like to modify/replace it with code that will limit the print to the first page of each file:
Function PrintDigSafePackage()

Dim cFile As String
Dim RetVal As Long
Dim cAction
Dim cPrinterName

cAction = "printto"

cPrinterName = "DPW_MGT - Ricoh MP6000"

' Get files to print
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("select * from DigSafePackagePrint order by Address, Sort")

'Print Files

Do While rs.EOF = False
   
    If Len(Dir(rs("FilePath"))) Then
    cFile = rs!FilePath
    RetVal = ShellExecute(0, cAction, cFile, cPrinterName, "", 1)
    
    End If
    cFile = ""
    rs.MoveNext
Loop
rs.close
Set rs = Nothing


End Function

Open in new window


Please help.

Jeff
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

This may not be easy.

ShellExecute does not have any parameters to set the "page" to print.

You can probably "Open" the file instead, then add in a call to the printer Object and set it to print Page 1.

Either that or use "SendKeys" (not recommended) to "Manually" set this up.
I am sure an expert will be along who can go into more detail about manipulating the Printer settings.

Another "Option" ( I use that term lightly) to get this going currently, might be to simply create a second set of pdfs that only contain "Page 1"...?
Avatar of wellesleydpw
wellesleydpw

ASKER

Thanks Boag2000,
No one else has responded yet, can you tell me where to look into your Open and Call solution?
Jeff
In your shellExecute code you would change cAction to "Open"
Then see the code here...:
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=101
I've got this working using Acroexch which I hadn't known about previously:

Function PrintDigSafePackage()
Dim App As Object
Dim AVDoc As Object
Dim rs As DAO.Recordset

Dim retcd As Integer
Dim cFile As String

Set App = CreateObject("Acroexch.app")
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set rs = CurrentDb.OpenRecordset("select * from DigSafePackagePrint order by Address, Sort")

' Cycle through files to print
Do While rs.EOF = False
   
    If Len(Dir(rs("FilePath"))) Then
    cFile = rs!FilePath
 
    'Open File
    retcd = AVDoc.Open(cFile, "Title")
    'Print first page only (i.e. page 0)
    retcd = AVDoc.PrintPages(0, 0, 0, 1, 1)
    
    AVDoc.close (1)
    
    End If
    cFile = ""
    rs.MoveNext
Loop
rs.close

Set rs = Nothing
Set AVDoc = Nothing
End Function

Open in new window


Hope this helps someone in the future.
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I do have the full version (Adobe X Pro) and honestly, I don't know how to tell if the code requires it or not.  Because you're the only one who assisted and I did need to open first, I'm giving you the points.  Thanks for your help.
Jeff
Nope, ...you answered your own question, so that is the post you should accept.
If you accept my post, it is marked as the "Solution".

This will confuse other member searching here for the same issue.
They will wonder how my post is a "Solution"

;-)

Please click the "Request Attention" link and ask that your post: (37783062) be changed to the accepted solution.

;-)

Enjoy the weekend...

;-)

Jeff