Copy link to clipboard
Copied
I need to be able to process a stack of PDF documents.
What I need: to always print-out only the first page of all documens.
These are invoices with sometimes 5 pages, sometimes 2....but I only need to archive the frontpage.
So: opening each of these maybe 100 documents and always only print the first page manually seems a bit like "nonsense" to me.
Could do this on a friends machine who has an Acrobat Pro X installed.
Help appreciated
Anna
This can be done in Acrobat Pro using an Action. Create a new Action with
the following JavaScript command:
this.print(false,0,0,true);
This will silently print the first page of all the files you will run this
Action on (to the last used printer).
Copy link to clipboard
Copied
This can be done in Acrobat Pro using an Action. Create a new Action with
the following JavaScript command:
this.print(false,0,0,true);
This will silently print the first page of all the files you will run this
Action on (to the last used printer).
Copy link to clipboard
Copied
Great! Many thanks
Is there actually a kind of marketplace for Javascipts for Adobe Acrobat Pro somewhere? ...
Really useful!
Copy link to clipboard
Copied
You're welcome!
I have a website where I sell many custom-made scripts that I've made for
Acrobat, but I was asked not to publish it here...
Copy link to clipboard
Copied
ok 😕 too bad. can you PM?
Copy link to clipboard
Copied
Sure... You can also google my handle-name and you'll find it.
Copy link to clipboard
Copied
Thank you very much.
Is there also a way to print the first and last pages of multiple PDF's?
Also is there a general formula for this?
Thanks!
Copy link to clipboard
Copied
Yes, like this:
this.print({ bUI: false, nStart: 0, bSilent: true});
this.print({ bUI: false, nStart: this.numPages-1, bSilent: true});
Copy link to clipboard
Copied
Thanks for your response.
Could you show a few examples?
How would I ask Acrobat to print just the last pages of several PDF's?
Copy link to clipboard
Copied
Use the code I just provided in an Action. It will print the first and last pages of each PDF that you process.
Copy link to clipboard
Copied
Is there a different command to save these to PDFs instead of sending them to the printer?
I tried setting my default printer as Adobe, but that didnt work with " this.print(false,0,0,true); "
Thanks for your help in advance!
Copy link to clipboard
Copied
Yes, it's possible to do that using the extractPages method, but you need to specify what file-name to use for each file.
The basic syntax would be something like this:
this.extractPages(0, 0, this.path.replace(/\.pdf$/i, "_first page.pdf"));
The code above will save the first page of each file into the same folder as the original, adding the "_first page" suffix to the file-name.
Copy link to clipboard
Copied
Thanks for your response!
This is what i did to work around:
1. Install CutePDF as a PDF printer, and print an individual file to prompt Adobe.
2. then ran the script you provided (slightly modified to print the first 2 pages - I feel like a genius here cuz I have absolutely no programming knowledge)
this.print(false,0,1,true);
Adobe prompts me a "Save as" window to save the file names, and since I need them to be the same, its working like a charm!!!
Thanks a lot man - mad props!
Copy link to clipboard
Copied
Try67, thanks very much for posting that script. It reflects exactly what I need to do for many thousands of pdfs. I've downloaded a trial of Acrobat Pro to see if I can get it to work (not being an Acrobat or Java Script expert by any means). Unfortunately when I create an action based on executing the Java Script you provided, a "Javascript Editor" pops open aslomg me to "put script title here." Which seems odd since I'm running an action called Extract 1st pages. Any idea where the problem is? Thanks! Mark
Copy link to clipboard
Copied
I used your scipt to print 1st page of multiple pdfs. It worded for awhile now printing whole file. /* this.print(false,0,0,true); */
Copy link to clipboard
Copied
or won't print at all!
Copy link to clipboard
Copied
Hi there, I have tried the JavaScript, it works well, just that each document I have choose "print current page" then I have to click "print" - is not run automatically? Is it possible to make run automatically?
Copy link to clipboard
Copied
From where are you running it, exactly? It should be silent, if you used the code I posted.
Copy link to clipboard
Copied
Hi , thanks for your reply.
firstly, I allocated all documents in a folder. then I open the action Wizard, then I choose the action. after that,
each PDF will pop up automatically. but i have to choose the first page (I only need to print the first page of each dcument). It save some time in opening each PDF, but i still have to choose " print current page", then " Print. please let me know if I have missed any steps? Thank you,
Copy link to clipboard
Copied
What commands did you add to your Action?
Copy link to clipboard
Copied
this.print(false,0,0,true);
this is the action I added
Copy link to clipboard
Copied
Do you want to print the current page, or the first page?
If the latter, try the code I provided above:
this.print({ bUI: false, nStart: 0, bSilent: true});
Also, make sure there are no other commands in your Action beside the one that executes this code.
Copy link to clipboard
Copied
Hi there, does anyone know a code that can be implied within a macro in Outlook to print all the pages except for the last one of a PDF?
The code I current have to print PDF's from an email is:
Sub OpenDossierFolder()
Dim sPath
Dim iReply As String
iReply = InputBox("Dossiernummer:")
If iReply = "" Then
Exit Sub
Else
sPath = "\\nlsvfil001\trismd\Trisdigdocs\" & iReply & "\"
Shell "C:\Windows\Explorer.exe """ & sPath & "", vbNormalFocus
End If
End Sub
Sub SaveEmailAttachmentsToFolder(OutlookFolderInInbox As String, _
ExtString As String, DestFolder As String)
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim MyDocPath As String
Dim I As Integer
Dim wsh As Object
Dim fs As Object
Dim sDate As Date
Dim aDate As String
On Error GoTo ThisMacro_err
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders(OutlookFolderInInbox)
I = 0
' Check subfolder for messages and exit of none found
If SubFolder.Items.Count = 0 Then
MsgBox "There are no messages in this folder : " & OutlookFolderInInbox, _
vbInformation, "Nothing Found"
Set SubFolder = Nothing
Set Inbox = Nothing
Set ns = Nothing
Exit Sub
End If
'Create DestFolder if DestFolder = ""
If DestFolder = "" Then
Set wsh = CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
MyDocPath = wsh.SpecialFolders.Item("mydocuments")
DestFolder = MyDocPath & "\" & Format(Now, "dd-mmm-yyyy hh-mm-ss")
If Not fs.FolderExists(DestFolder) Then
End If
End If
If Right(DestFolder, 1) <> "\" Then
DestFolder = DestFolder & "\"
End If
' Check each message for attachments and extensions
For Each Item In SubFolder.Items
For Each Atmt In Item.Attachments
If LCase(Right(Atmt.FileName, Len(ExtString))) = LCase(ExtString) Then
sDate = Item.SentOn
aDate = Format(sDate, "yyyymmddhhmm")
FileName = DestFolder & aDate & Item.SenderName & " " & Atmt.FileName
I = I + 1
End If
Next Atmt
Next Item
' Show this message when Finished
If I > 0 Then
' MsgBox "De PDF bestanden staan in de map: " _
' & DestFolder, vbInformation, "Finished!"
Else
MsgBox "No attached files in your mail.", vbInformation, "Finished!"
End If
' Clear memory
ThisMacro_exit:
Set SubFolder = Nothing
Set Inbox = Nothing
Set ns = Nothing
Set fs = Nothing
Set wsh = Nothing
'Set DestFolder = Nothing
Exit Sub
' Error information
ThisMacro_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: SaveEmailAttachmentsToFolder" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume ThisMacro_exit
'-----------------------------------------
End Sub
Sub Saveattachementstofolder()
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Msg As MailItem
Dim Messages As Selection
Dim ObjFolder As Outlook.Folder
Dim oMailItem As MailItem
Dim myCopiedItem As Outlook.MailItem
Dim x As Object
Dim olDestFolder As Outlook.MAPIFolder
Dim strFilelocation As String
strFilelocation = "C:\Facturen\"
On Error Resume Next
Kill (strFilelocation & ("*.*"))
On Error GoTo 0
Set ns = Application.GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders("Facturen printen")
Set ObjFolder = SubFolder
'Set ObjFolder = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Folders("Facturen printen")
Set Messages = ActiveExplorer.Selection
If Messages.Count = 0 Then
Exit Sub
End If
'-----------------------------------------
For Each Msg In Messages
Next
'-----------------------------------------
If Dir(strFilelocation, vbDirectory) = vbNullString Then
MkDir strFilelocation
End If
SaveEmailAttachmentsToFolder "Facturen printen", "", "C:\Facturen"
Shell "Explorer.exe /e,C:\Facturen", vbNormalFocus
Set olDestFolder = ns.GetDefaultFolder(olFolderInbox)
Set olDestFolder = olDestFolder.Folders("RIO RINTO")
Set olDestFolder = olDestFolder.Folders("Rio Tinto INVOICES")
Set ns = Nothing
Set Inbox = Nothing
Set SubFolder = Nothing
'-----------------------------------------
For Each Msg In ObjFolder.Items
Next
For Each Msg In ObjFolder.Items
Next
For Each Msg In ObjFolder.Items
Next
For Each Msg In ObjFolder.Items
Next
For Each Msg In ObjFolder.Items
Next
For Each Msg In ObjFolder.Items
Next
For Each Msg In ObjFolder.Items
Next
For Each Msg In ObjFolder.Items
Next
For Each Msg In ObjFolder.Items
Next
For Each Msg In ObjFolder.Items
Next
'-----------------------------------------
Set ns = Nothing
Set Inbox = Nothing
Set SubFolder = Nothing
Set Msg = Nothing
Set Messages = Nothing
Set ObjFolder = Nothing
Set oMailItem = Nothing
Set myCopiedItem = Nothing
Set x = Nothing
Set olDestFolder = Nothing
'Set strFilelocation = Nothing
End Sub
Sub batfile()
Dim batPath As String: batPath = "C:\bat\"
Call Shell(Environ$("COMSPEC") & " /c " & batPath & "\batchprint.bat", vbNormalFocus)
End Sub
Thanks in advance!