COM integration with PDF to save a file

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gonzoson
Posts: 5
Joined: 26 Jan 2019, 10:25

COM integration with PDF to save a file

10 Mar 2021, 21:15

I am trying to create a script that will extra text from fields in a pdf and use that data to save and name the pdf. I managed to find code to extract data from the opened pdf and another code to save the pdf. But I cant figure out how to combine them two. I am hoping to get some help here.



Here is the first half of the code that extracts the information.

Code: Select all

F8::
oAcrobat := ComObjCreate("acroExch.App")
oAcrobatdoc := ComObjCreate("acroexch.avdoc")      ; create an document object
oAcrobat.show() ; make the application object visible or .hide it
Part1Document := ComObjCreate("AcroExch.PDDoc")
App := ComObjCreate("AcroExch.App")
AVDoc := App.GetActiveDoc()
PDDoc := AVDoc.GetPDDoc()
JSO	:= PDDoc.GetJSObject

field_name := JSO.GetNthFieldName(5)
last_name := JSO.GetField(field_name).Value ;gets the last name
last_name := JSO.GetField(field_name).Value := "test"

field_name := JSO.GetNthFieldName(6)
first_name := JSO.GetField(field_name).Value ;gets the first name
field_name := JSO.GetNthFieldName(16)
dob := JSO.GetField(field_name).Value ;gets the dob

file_name := last_name . "_" . first_name . "_" . StrReplace(dob, "/", "") . "_i693" ;sets up a file name

MsgBox, % file_name
Here is the second part of the code that should save the file.

Code: Select all

App := ComObjCreate("AcroExch.App")
AVDoc := ComObjCreate("AcroExch.AVDoc")


PVDoc := AVDoc.GetPDDoc()
PDSaveIncremental       := 0x0000   ;/* write changes only */ 
PDSaveFull              := 0x0001   ;/* write entire file */ 
PDSaveCopy              := 0x0002   ;/* write copy w/o affecting current state */
PDSaveLinearized        := 0x0004   ;/* write the file linearized for 
PDSaveBinaryOK          := 0x0010   ;/* OK to store binary in file */
PDSaveCollectGarbage    := 0x0020   ;/* perform garbage collection on

PVDoc.save(PDSaveFull,  A_Desktop . "\" . file_name . ".pdf")

PVDoc.close()
App.CloseAllDocs()
App.exit()
return
I am trying to open a NewForm.pdf manually. Fill out the form manually. Have AHK extract the information from the opened form and save the form under new file name that will preserve the original file and have new file name contain the extracted information.
casperharkin
Posts: 11
Joined: 27 Sep 2017, 20:52

Re: COM integration with PDF to save a file

11 Mar 2021, 00:36

Here you go.

Code: Select all

F8::
	oAcrobat := ComObjCreate("acroExch.App")
	oAcrobatdoc := ComObjCreate("acroexch.avdoc")      ; create an document object
	oAcrobat.show() ; make the application object visible or .hide it
	Part1Document := ComObjCreate("AcroExch.PDDoc")
	App := ComObjCreate("AcroExch.App")
	AVDoc := App.GetActiveDoc()
	PDDoc := AVDoc.GetPDDoc()
	JSO	:= PDDoc.GetJSObject
	
	field_name := JSO.GetNthFieldName(5)
	last_name := JSO.GetField(field_name).Value ;gets the last name
	last_name := JSO.GetField(field_name).Value := "test"
	
	field_name := JSO.GetNthFieldName(6)
	first_name := JSO.GetField(field_name).Value ;gets the first name
	field_name := JSO.GetNthFieldName(16)
	dob := JSO.GetField(field_name).Value ;gets the dob
	
	file_name := last_name . "_" . first_name . "_" . StrReplace(dob, "/", "") . "_i693" ;sets up a file name
	
	MsgBox, % file_name
	
	PDSaveIncremental       := 0x0000   ;/* write changes only */ 
	PDSaveFull              := 0x0001   ;/* write entire file */ 
	PDSaveCopy              := 0x0002   ;/* write copy w/o affecting current state */
	PDSaveLinearized        := 0x0004   ;/* write the file linearized for 
	PDSaveBinaryOK          := 0x0010   ;/* OK to store binary in file */
	PDSaveCollectGarbage    := 0x0020   ;/* perform garbage collection on
	
	PDDoc.save(PDSaveFull,  A_Desktop . "\" . file_name . ".pdf")
User avatar
Xeo786
Posts: 760
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: COM integration with PDF to save a file

11 Mar 2021, 00:37

link about how to combine pdf using acrobat

https://www.autohotkey.com/boards/viewtopic.php?t=80087
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
gonzoson
Posts: 5
Joined: 26 Jan 2019, 10:25

Re: COM integration with PDF to save a file

11 Mar 2021, 13:41

casperharkin wrote:
11 Mar 2021, 00:36
Here you go.

Code: Select all

F8::
	oAcrobat := ComObjCreate("acroExch.App")
	oAcrobatdoc := ComObjCreate("acroexch.avdoc")      ; create an document object
	oAcrobat.show() ; make the application object visible or .hide it
	Part1Document := ComObjCreate("AcroExch.PDDoc")
	App := ComObjCreate("AcroExch.App")
	AVDoc := App.GetActiveDoc()
	PDDoc := AVDoc.GetPDDoc()
	JSO	:= PDDoc.GetJSObject
	
	field_name := JSO.GetNthFieldName(5)
	last_name := JSO.GetField(field_name).Value ;gets the last name
	last_name := JSO.GetField(field_name).Value := "test"
	
	field_name := JSO.GetNthFieldName(6)
	first_name := JSO.GetField(field_name).Value ;gets the first name
	field_name := JSO.GetNthFieldName(16)
	dob := JSO.GetField(field_name).Value ;gets the dob
	
	file_name := last_name . "_" . first_name . "_" . StrReplace(dob, "/", "") . "_i693" ;sets up a file name
	
	MsgBox, % file_name
	
	PDSaveIncremental       := 0x0000   ;/* write changes only */ 
	PDSaveFull              := 0x0001   ;/* write entire file */ 
	PDSaveCopy              := 0x0002   ;/* write copy w/o affecting current state */
	PDSaveLinearized        := 0x0004   ;/* write the file linearized for 
	PDSaveBinaryOK          := 0x0010   ;/* OK to store binary in file */
	PDSaveCollectGarbage    := 0x0020   ;/* perform garbage collection on
	
	PDDoc.save(PDSaveFull,  A_Desktop . "\" . file_name . ".pdf")
This works thank you so much. I just need to figure out what you did difrently.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Kodakku, TAC109 and 367 guests