Send PDF Files to EverNote
UPDATE: Since releasing version 188.8.131.522 in September 2008, Evernote for Windows now supports import, indexing, and preview of PDF files. The Mac version supported this several months prior. The work-around below is no longer needed (but still fun to try if you want to experiment with and learn more about Ghostscript).
UPDATE 2 (May 2009): A reader pointed out to me that this macro is still useful because, even through Evernote now supports PDFs, it does not support indexing the images inside those PDFs. This has been requested many times over in the Evernote forums with no clear delivery date. So, if indexing the images inside your PDFs is important, it may still be worth tinkering with this script.
As I mentioned in my EverNote vs. OneNote post, one of the key weaknesses of EverNote is its inability to handle PDF files. To get around that, I created a script to send the content of PDF files to EverNote as JPEG images. This is in the form of an Outlook VBA macro. I used it to quickly capture hand-written notes scanned into my office copier/scanner. The notes would arrive via email in an attached PDF file.
To use the script, you must set up an Outlook rule to trigger based on the mail address of your copier/scanner. The script then saves the attachment to a folder of your choice (edit path below), then calls Ghostscript to generate a JPEG file for each page. Note that since I already had PDF995 installed, I just used the Ghostscript executables that come bundled with that tool. You can install the PDF995 tool and edit the path in the VBA script below to point to those executables… or you can probably find or compile a standalone version. By the way, PDF995 is an excellent free tool and does a fantastic job distilling content into PDF files.
The last pre-requisite is setting up the auto-import folder in EverNote and enabling it. You can search the EverNote help for instructions on this. Edit the script below to reflect your EverNote auto import folder.
If you don’t want to run this from Outlook, you could just grab certain portions of the script and run them from a DOS batch file or from a hot key. Enjoy!
Sub PDFRipper(MyMail As Outlook.MailItem)
' Converts PDF files received via email to JPEG for auto-import
' to EverNote. It was loosely tested with Outlook 2003, see
' Manage-This.com for disclaimer and details of the Creative
' Commons license.
' Carl C. 2007
' You'll never call this function, Outlook will call it automatically
' as part of the rules process, and it will pass in the MyMail object
' without you ever having to worry about it.
Dim strID, strCommand, batchFile As String
Dim PDFfile, PDFpath, JPGfile, JPGpath As String
Dim olns As Outlook.NameSpace
Dim objMsg As Outlook.MailItem
strID = MyMail.EntryID
Set olns = Application.GetNamespace("MAPI")
Set objMsg = olns.GetItemFromID(strID)
On Error GoTo ErrorHandler
'This code uses the GhostScript utility to convert the PDF file to JPEG format.
'It assumes you already have GhostScript installed at the path identified by
'GSpath (update as needed). Note that I am using the GhostScript binaries that
'come bundled with the PDF995 software.
Const GSpath = "C:\\Program Files\\pdf995\\res\\convert"
'Folder to store PDFs (must already exist)
Const PDFfolder = "C:\\Documents and Settings\\UserName\\My Documents\\Personal Docs\\Scans\\"
'Set up AutoImport directory for EverNote, then update this
'link to point to it. Folder must already exist.
Const JPGfolder = "C:\\Documents and Settings\\UserName\\My Documents\\My EverNote Files\\Auto Import\\"
' Skip anything that's not a mail message (calendar items, tasks, etc.)
If objMsg.Class = olMail Then
Set objAttachments = objMsg.Attachments
Counter = objAttachments.Count
'Only execute if there is at least one attachment in the message
If Counter > 0 Then
'Walk through the attachment collection archiving each one
For i = objAttachments.Count To 1 Step -1
'Build strings to contain file & path names
PDFfile = objAttachments.Item(i).FileName
PDFfile = Replace(PDFfile, ".PDF", ".pdf")
PDFpath = PDFfolder & Strings.Format(objMsg.ReceivedTime, "yyyy.mm.dd.hhnn") & "\\"
'GS replaces %d below with the page number; need a double (%%) to escape
'the % character and preserve it when command is run from DOS batch file
JPGfile = Replace(PDFfile, ".pdf", "%%d.jpg")
JPGpath = JPGfolder & JPGfile
batchFile = GSpath & "\\cvt.bat"
'Create a subfolder to hold the PDF files
If Dir(PDFpath, vbDirectory) = "" Then
'Now add the filename to make the PDF path complete
PDFpath = PDFpath & PDFfile
' Save the attachment to disk then remove it from the email
'Build command string for converting PDF to JPG
strCommand = "gswin32c -q -dNOPAUSE -dJPEGQ=90 -sDEVICE=jpeg -r200 -sOutputFile=""" _
& JPGpath & """ """ & PDFpath & """ -c quit"
strCommand = Replace(strCommand, "\\", "\")
'The end result will look something like this. Enable MsgBox to see it.
'gswin32c -q -dNOPAUSE -dJPEGQ=90 -sDEVICE=jpeg -r200 -sOutputFile="D:\PathName\filename%d.jpg" "D:\AnotherPath\filename.pdf" -c quit
'Create the DOS batch file that will execute the GhostScript commands
Dim FileNum As Integer
FileNum = FreeFile 'Grab the next available file number
Open batchFile For Output As #FileNum 'Use "Output" not "Append" to overwrite (or create) file
Print #FileNum, "c:"
Print #FileNum, "cd " & Replace(GSpath, "\\", "\")
Print #FileNum, strCommand
'The "0" option makes it run in a hidden DOS window
shell batchFile, 0
End If 'If Counter > 0 Then
End If 'If objMsg.Class = olMail
Set objMsg = Nothing
Set olns = Nothing
MsgBox "PDFRipper( ) Subroutine" & vbCrLf & vbCrLf _
& "Error Code: " & Err.Number & vbCrLf & Err.Description
Comments are closed.