Skip to content
Newer
Older
100644 81 lines (63 sloc) 2.2 KB
930026f @tmoore82 third-commit
authored Sep 6, 2012
1 'PDF-txt-Word
97f8e91 @tmoore82 fourth-commit
authored Sep 7, 2012
2 '1.1
3 '9/6/2012 by tmoore82
930026f @tmoore82 third-commit
authored Sep 6, 2012
4
5 'This script converts PDFs to plain text, then copies and pastes that plain text to a new Word document
6 'This can be used when you want the text from a PDF without any of the formatting,
7 'especially when you suspect the document is corrupted.
8
9 'Users should save the pdf to their Desktop before running the script.
10
11 'string to hold file path (DMM is short for Don't Mind Me, as this is a space for temporary files the user can ignore.)
12 Dim strDMM
13 strDMM = "C:\dmm"
14
15 'make this directory if it doesn't exits
16 On Error Resume Next
17 MkDir strDMM
18 On Error GoTo 0
19
20 'get the username to go to the right filepath
21 Dim strUser
22 strUser = InputBox("What is your username?" & chr(13) & chr(13) & "(Example: [myname])", "Username")
23
24 'get the file name to process
25 Dim TheFile
26 TheFile = InputBox("What is the file name?" & chr(13) & chr(13) & "(Example: [file.pdf])", "Name of File")
27
28 'declare some acrobat variables
29 Dim AcroXApp
30 Dim AcroXAVDoc
31 Dim AcroXPDDoc
32
33 'open acrobat
34 Set AcroXApp = CreateObject("AcroExch.App")
35 AcroXApp.Hide
36
37 'open the document we want
38 Set AcroXAVDoc = CreateObject("AcroExch.AVDoc")
39 AcroXAVDoc.Open "c:\Users\" & strUser & "\Desktop\" & TheFile, "Acrobat"
40
41 'make sure the acrobat window is active
42 AcroXAVDoc.BringToFront
43
44 'I don't know what this line does. As with a lot of this, I copied it from code online.
45 Set AcroXPDDoc = AcroXAVDoc.GetPDDoc
46
47 'activate JavaScript commands w/Acrobat
48 Dim jsObj
49 Set jsObj = AcroXPDDoc.GetJSObject
50
51 'save the file as plain text
52 jsObj.SaveAs "C:\dmm\" & "pdf-plain-text.txt", "com.adobe.acrobat.plain-text"
53
54 'close the file and exit acrobat
55 AcroXAVDoc.Close False
56 AcroXApp.Hide
57 AcroXApp.Exit
58
59 'Create a Word Object
60 Dim objWord
61 set objWord = CreateObject("Word.Application")
62
97f8e91 @tmoore82 fourth-commit
authored Sep 7, 2012
63 'insert the file into Word
930026f @tmoore82 third-commit
authored Sep 6, 2012
64 With objWord
65 .Visible = False
97f8e91 @tmoore82 fourth-commit
authored Sep 7, 2012
66 .Documents.Add()
67 .Selection.InsertFile "C:\dmm\pdf-plain-text.txt"
68 'the next three lines lines are to change everything to our default style at work.
69 'if you just want the plain text and want to go from there, you don't need them.
70 .Selection.WholeStory
71 .Selection.Style="Body Text"
72 .Selection.Homekey
930026f @tmoore82 third-commit
authored Sep 6, 2012
73 End With
74
75 'make Word visible
76 With objWord
77 .Visible = True
78 End With
79
80 'Remind the user to save
81 MsgBox ("Save the document.")
Something went wrong with that request. Please try again.