Delete PDF Pages through Adobe COM

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Delete PDF Pages through Adobe COM

01 May 2018, 17:26

Hi all, i'm trying to delete pages from a PDF via COM with Adobe. I think i've got the right idea below but having trouble with just one line. Specifically the one that would delete the pages.

I found PPDocDeletePages details here: https://help.adobe.com/livedocs/acrobat ... index.html

Parameters

Code: Select all

PDDocDeletePages(PDDoc doc, ASInt32 firstPage, ASInt32 lastPage, ProgressMonitor progMon, void* progMonClientData)


Code: Select all

DetectHiddenWindows, On
 
doc1 := A_Desktop "\Test.pdf"
 
AcroApp := ComObjCreate("AcroExch.App")
Part1Document := ComObjCreate("AcroExch.PDDoc")
 
Part1Document.Open(doc1)
 
;Part1Document.PDDocDeletePages(doc1, 0, 4, NULL, NULL) ;Fail 1 ;Unknown: PDDocDeletePages
 
;AcroExch.PDDoc.PDDocDeletePages(doc1, 0, 4, NULL, NULL) ;Fail 2, I know this is bad code but still does not cause an error.
 
;doc1.PDDocDeletePages(doc1, 0, 4, NULL, NULL) ;Fail 3, I know this is bad code but still does not cause an error.
 
Part1Document.Save(1,doc1)
 
run, %doc1%
 
Msgbox, Pages 1-4 are not deleted & pause to 'open script' and view executed lines.
 
 
;*** My code somewhat derived from the below script, credit BlackHolyMan
 
/*
	
	
	#SingleInstance Force
	DetectHiddenWindows, on
	
	doc1 := A_MyDocuments "\SampleDocument.pdf"
	doc2 := A_MyDocuments "\SampleDocument2.pdf"
	img1 := A_MyDocuments "\image1.bmp"
	
	AcroApp := ComObjCreate("AcroExch.App")
	Part1Document := ComObjCreate("AcroExch.PDDoc")
	Part1Document.Open(doc1)
	JSo := Part1Document.GetJSObject()
	f := JSo.getField("image1")
	
	try
		f.buttonImportIcon(img1)
	Part1Document.Save(1,doc2)
	
	sleep 1000
	
	run %doc2%
	ExitApp
So my problem is this line, i'm not sure what to put %here%.PDDocutDeletePages(params,1,2,3,4)

Code: Select all

Part1Document.PDDocDeletePages(doc1, 0, 4, NULL, NULL) ;Fail 1 ;Unknown: PDDocDeletePages
Blackholyman, if you see this I have seen your posts with Adobe and always find a solution. I really hope you can help out, or anyone for that matter. :D

Thanks in advance.

Vh
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Delete PDF Pages through Adobe COM

01 May 2018, 19:14

Working with Acrobat COM can be quite tricky. Most Microsoft programs have everything hierarchied in one application object. But Acrobat uses a bunch of separate objects: App, AVDoc, PDDoc, PDPage, etc.

Here is an example of opening a PDF, deleting a page, and saving.

Code: Select all

F12::
	PDDoc := ComObjCreate("AcroExch.PDDoc")
	PDDoc.Open(A_Desktop "\Test\Test.pdf")
	PDDoc.OpenAVDoc("") ; causes display
	MsgBox Wait
	PDDoc.DeletePages(1,1)
	MsgBox Wait
	PDDoc.Save(1,  A_Desktop "\Test\Test2.pdf")
	PDDoc.Close()
return
This does it in spurts so that you can see what is going on.

This does it all in the background:

Code: Select all

F12::
	PDDoc := ComObjCreate("AcroExch.PDDoc")
	PDDoc.Open(A_Desktop "\Test\Test.pdf")
	PDDoc.DeletePages(1,1)
	PDDoc.Save(1,  A_Desktop "\Test\Test2.pdf")
	PDDoc.Close()
return
It is important to realize that pages are zero-indexed, meaning the first page is 0. The above examples delete the second page (index 1 to index 1).

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
JoeWinograd
Posts: 2177
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Delete PDF Pages through Adobe COM

02 May 2018, 01:43

Hi FG,
That's a nice piece of code...works perfectly! Is there a similar COM call that extracts pages? I'm hoping for something like PDDoc.ExtractPages(first,last). I know that's not right, but have been unable to find an ExtractPages object in AVDoc, PDDoc, or PDPage, and am hoping you know it off the top of your head. Thanks much, Joe
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: Delete PDF Pages through Adobe COM

02 May 2018, 08:46

Wonderful, FanaticGuru! This works well. The only issue I have encountered is after this has been executed, Adobe crashes when I try and close the window manually. Any ideas? Thanks!!!
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Delete PDF Pages through Adobe COM

02 May 2018, 13:38

Vh_ wrote:Wonderful, FanaticGuru! This works well. The only issue I have encountered is after this has been executed, Adobe crashes when I try and close the window manually. Any ideas? Thanks!!!
You should not have to close the PDF manually. With the second code, you should never even see a PDF. If you want to work on an PDF that is already open and active that is possible also.

Also you should be careful of any ComObjCreate("AcroExch. stuff you don't need. This could cause unexpected results.

If you are attempting to integrate this into your own script, you might post your code to see if you are doing something unexpected. It is definitely possible to cause Acrobat to crash through COM with very small mistakes. Acrobat does not do much error checking on parameters and commands. One wrong parameter can cause a problem not just immediately but down the road. Not keeping AVDoc and PDDoc straight might cause a problem similar to yours.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Delete PDF Pages through Adobe COM

02 May 2018, 16:48

JoeWinograd wrote:Hi FG,
That's a nice piece of code...works perfectly! Is there a similar COM call that extracts pages? I'm hoping for something like PDDoc.ExtractPages(first,last). I know that's not right, but have been unable to find an ExtractPages object in AVDoc, PDDoc, or PDPage, and am hoping you know it off the top of your head. Thanks much, Joe
There is no ExtractPages but you can achieve the same result with a little more effort than a single command.

One way is just to use the Delete example and Delete all the pages you do not want and save the result.

If you really want to pick the pages you can create a new blank PDF and InsertPages from the original into the new blank to create a new PDF with just the pages you want.

Code: Select all

F11::
	PDDoc := ComObjCreate("AcroExch.PDDoc")
	PDDoc.Open(A_Desktop "\Test\Test.pdf")
	;~ AVDoc := PDDoc.OpenAVDoc("") ; create a AVDoc to display a PDDoc
	;~ MsgBox Wait
	PDDoc2 := ComObjCreate("AcroExch.PDDoc")
	PDDoc2.Create()
	PDDoc2.InsertPages(-1, PDDoc, 1, 2, 0) ; index-0, add at beginning from PDDoc the second to third pages without bookmarks
	;~ AVDoc2 := PDDoc2.OpenAVDoc("") ; create a AVDoc to display a PDDoc
	;~ AVDoc2.SetTitle("Title - Extracted Pages") ; Not really necessary to give title, changed by Save to filename
	;~ MsgBox Wait
	PDDoc2.Save(1,  A_Desktop "\Test\Test2.pdf")
	PDDoc.Close()
	PDDoc2.Close()
return
You can uncomment lines to slow things down and show what is happening.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
JoeWinograd
Posts: 2177
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Delete PDF Pages through Adobe COM

03 May 2018, 00:58

FanaticGuru wrote:There is no ExtractPages
Thanks for confirming that.
FanaticGuru wrote:use the Delete example and Delete all the pages you do not want and save the result
I considered that, but thought that it would not perform as well as doing the extraction.
FanaticGuru wrote:If you really want to pick the pages you can create a new blank PDF and InsertPages from the original into the new blank to create a new PDF with just the pages you want.
Great idea! Your code works perfectly! Thanks much, Joe
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: Delete PDF Pages through Adobe COM

03 May 2018, 17:59

FanaticGuru, thanks for all your help! I've made great progress. I've incorporated the methods you have provided and had success.
FanaticGuru wrote:
Vh_ wrote: If you are attempting to integrate this into your own script, you might post your code to see if you are doing something unexpected...
FG
My goal is to create more than one additional file with varying conditions. The condition is found on a data sheet in Excel. I have it bricks of page ranges and those that are the same page count are to be put into its own file. Here is an example of what i'm trying to do, see lines 44-49 and 85-88 for the desired code intention. Look for the lines between commented asterisks to find.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
Start:

FileSelectFile, LetterFile, 1,, Select a PDF, PDF Document (*.pdf) ;Choose a PDF

SplitPath, LetterFile, SelectedFile ;might want to strip out .pdf from name. will need to test behavior.

If LetterFile = "" ;need to fix so cancel will exit script.
{
	ExitApp
}


XL := ComObjActive("Excel.Application")
PDDoc := ComObjCreate("AcroExch.PDDoc")
NewFileName = EXTRACTS FROM %SelectedFile%
Msgbox, % NewFileName
PDDoc.Open(LetterFile)
PDDoc.OpenAVDoc("") ; causes display
;Msgbox, % PDDoc.GetNumPages()
PDDoc2 := ComObjCreate("AcroExch.PDDoc")
PDDoc2.Create() ;create the second document to insert pages into


;[~First loop to extract pages into own files~]

number = 0 ;start at 0 so cell offset incriment starts at 1 in loop.

Loop
{
	number++ ;incriment by 1
	FirstPage := XL.ActiveCell.Offset(-number,0).Value ;get first page number
	LastPage := XL.ActiveCell.Offset(-number,1).Value ;get last page number to right of cell point
	Count := XL.ActiveCell.Offset(-number,2).Value
	
	If (Count = "6")
	{
		break ; stop when we find the majority.
	}
;*************************************************************************************************************************************************************************
If (FirstPage = "") ;if FirstPage is null, break out of the loop. 
		
	{
		Index++
		PPDoc%Index% := := ComObjCreate("AcroExch.PDDoc") ; create new instance and file for next group and continue. Need to find out how.
	}
;*************************************************************************************************************************************************************************
	
	PDDoc2.InsertPages(-1, PDDoc, firstPage, Count, 0) ; index-0, add at beginning from PDDoc the second to third pages without bookmarks
}

breakpoint := number - 1 ;let us know where you stopped when you found count 6.


;[~Second loop to delete extracted pages leaving remainder majority into own file~]

number = 0 ;Reset to delete.

Loop
{
	number++ ;incriment by 1

	FirstPage := XL.ActiveCell.Offset(-number,0).Value ;get first page number
	LastPage := XL.ActiveCell.Offset(-number,1).Value ;get last page number to right of cell point
	Count := XL.ActiveCell.Offset(-number,2).Value

	If (Count = "6") ;if you find the majority, stop.
	{
		break
	}
	
	If (FirstPage = "") ;if FirstPage is null, break out of the loop.
	{
		break ; stop when we find the majority.
	}

	PDDoc.DeletePages(FirstPage, LastPage) ;pages are 0 indexed. Page 1 = 0 ;delete range
}

;*************************************************************************************************************************************************************************
;Finally save all the created variable objects that exist. 
Loop %Index%[A_Index]
{
	PPDoc%Index%[A_Index].Save(1, SomeVar) ; is this possible?
}
;*************************************************************************************************************************************************************************

PDDoc.OpenAVDoc("") ; causes display
PDDoc2.OpenAVDoc("") ; causes display

PDDoc.Save(1, LetterFile)
PDDoc2.Save(1, NewFileName)

PDDoc.Close()
PDDoc2.Close()

ObjRelease(PPDoc)
ObjRelease(PPDoc2)

ExitApp
I'm thinking maybe I could store the object++ names in a file with FileAppend then read them to save all the separate files. Someone has also suggested using a class but not sure where to do from here.

Thanks!
Vh
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Delete PDF Pages through Adobe COM

03 May 2018, 19:15

Can you post an example of the Excel sheet? An actual xls file, picture, whatever so I can see the page data to better understand.

Is your Excel just something like this:

Code: Select all

R/C	A	B
1	4	6
2	8	13
3	15	15
Where you would want to build a new PDF from pages 4-6, 8-13, 15?

Constructing a new PDF from pages of a source PDF based on page information from Excel is all very doable.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: Delete PDF Pages through Adobe COM

08 May 2018, 16:42

FanaticGuru,

Here is what I ended up with and it works quite well! Thanks for all your help.

Code: Select all

#SingleInstance,Force
Gui, Font, s14 underline, Calibri
Gui, Add, text, x10, Target File
Gui, Font, s8 Normal, 
Gui, Add, edit, Disabled x10 y35 h25 w400 vFilePath, Select a File..
Gui, add, button, x410 y33 h28 w51 gLetterFile, Browse..
Gui, Font, s13.5 underline, Calibri
Gui, Add, text, x10, Processing Summary
Gui, Font, s10 normal, Calibri
Gui, Add, text, x11 y100, Start Page
Gui, Add, text, x96 y100, End Page
Gui, Add, text, x181 y100, Page Count
Gui, Add, text, x266 y100, Letters Processed
Gui, Add, Edit, x10 y115 w80 vS_Page
Gui, Add, Edit, x95 y115 w80 vE_Page 
Gui, Add, Edit, x180 y115 w80 vP_Count 
Gui, Add, Edit, x265 y115 w100 vL_Processed 
Gui, Add, Button, x370 y114 gStart, Process
Gui, Show
return




LetterFile:
FileSelectFile, LetterFile, 1,, Select a PDF, PDF Document (*.pdf) ;Choose a PDF
SplitPath, LetterFile, SelectedFile 
SplitPath, LetterFile,, dir
GuiControl, , FilePath, %LetterFile%
Gui, Submit
Gui, Show
return



Start:
XL := ComObjActive("Excel.Application")
PDDoc := ComObjCreate("AcroExch.PDDoc")
PDDoc.Open(LetterFile)
;PDDoc.OpenAVDoc("") ; causes display
;Msgbox, % PDDoc.GetNumPages() 
PDDoc2 := ComObjCreate("AcroExch.PDDoc") 
	PDDoc2.Create() ;create the second document to insert pages into


;[~First loop to extract pages into own files~]

number = 0 ;start at 0 so cell offset increment starts at 1 in loop.
Loop
{
	NewFile:
	number++ ;incriment by 1
	FirstPage := XL.ActiveCell.Offset(-number,0).Value ;get first page number
	LastPage := XL.ActiveCell.Offset(-number,1).Value ;get last page number to right of cell point
	Count := XL.ActiveCell.Offset(-number,2).Value
	GuiControl,, S_Page, %FirstPage%
	GuiControl,, E_Page, %LastPage%
	GuiControl,, P_Count, %Count%
	GuiControl,, L_Processed, %number%
	If (Count = "Count Page")
	{
		NewFileName2 = %dir%\EXTRACTS %SelectedFile% - %Count% Page Letters.pdf
		PDDoc2.Save(1, NewFileName2)
		break ; stop when we hit the end
	}
	If (FirstPage = "") ;if FirstPage is null, break out of the loop.
	{
		;create new instance and file for next group and continue
		;PDDoc2.OpenAVDoc("") ; causes display
		If (LastCount = "")
		{

			NewFileName2 = %dir%\EXTRACTS %SelectedFile% - %Count% Page Letters.pdf
			PDDoc2.Save(1, NewFileName2)
			msgbox, New File: %NewFileName2%
		}
		Else
		{
			NewFileName = %dir%\EXTRACTS %SelectedFile% - %LastCount% Page Letters.pdf
			PDDoc2.Save(1, NewFileName)
			msgbox, New File: %NewFileName%
		}
		PDDoc2.Close()
		verify := number + 1
		;msgbox, % verify
		VerifyNextCount := XL.ActiveCell.Offset(-verify,2).Value
		If (VerifyNextCount != "Count Page")
		{
			msgbox, Next New File Pages: %VerifyNextCount%
			PDDoc2.Create() ;create a new instance
		}
		GoTo, NewFile
	}
	PDDoc2.InsertPages(-1, PDDoc, firstPage, Count, 0) ; index-0, add at beginning from PDDoc the second to third pages without bookmarks
	LastCount = %Count%
}

PDDoc.OpenAVDoc("") ; causes display
PDDoc2.OpenAVDoc("") ; causes display
msgbox, done
;PDDoc.Save(1, LetterFile)
;PDDoc2.Save(1, NewFileName)
PDDoc.Close()
PDDoc2.Close()
ObjRelease(PPDoc)

;Written by Vh_
;Credit - Thanks to FanaticGuru and AutoHotkey Community for assistance! May 2018
Excel Example below. Column A and B are page ranges, start and end. C is page count. I have them split into regions so when it his a blank cell (like 4 and 7), make a new file.

Code: Select all

[R/C] a     b      c  
      1 50    55    5
      2 65    70    5
      3 72    77    5
      4 
      5 103 109   6
      6 681 687   6
      7 
      8 350 353   3
      9 561 564   3
    10 572 575   3


The last thing i'd like to look into is setting the value of a fillable field on a PDF, perhaps better suited for another thread but I thought i'd ask anyway :)
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Delete PDF Pages through Adobe COM

08 May 2018, 18:52

Vh_ wrote:
The last thing i'd like to look into is setting the value of a fillable field on a PDF, perhaps better suited for another thread but I thought i'd ask anyway :)
Here are two ways to go about working with fields in a PDF.

Code: Select all

F12::
	AFormAut := ComObjCreate("AFormAut.App")
	for Field in AFormAut.Fields
	{
		fNum := A_Index - 1
		fName := Field.Name
		fValue := Field.Value
		MsgBox % "Field Number = " fNum "`nField Name = " fName "`nField Value = " fValue
	}
	AFormAut.Fields("Your Name").Value := "Fanatic Guru"
return

F11::
	App := ComObjCreate("AcroExch.App")
	AVDoc := App.GetActiveDoc()
	PDDoc := AVDoc.GetPDDoc()
	JSO	:= PDDoc.GetJSObject
	Loop % JSO.NumFields
	{
		fNum := A_Index - 1
		fName := JSO.GetNthFieldName(fNum)
		fValue := JSO.GetField(fName).Value
		MsgBox % "Field Number = " fNum "`nField Name = " fName "`nField Value = " fValue
	}
	JSO.GetField("Your Name").Value := "Fanatic Guru"
return
Both of these work on the current active PDF.

The first uses Acrobat more directly while the second taps into the JavaScript abilities of Acrobat.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: Delete PDF Pages through Adobe COM

09 May 2018, 16:27

FanaticGuru,

I can't thank you enough for this fantastic code. I do want to note that the first example did not work for setting the value, the java method works just fine and not concerned about it. ;)

My next goal is to achieve is to do the advanced search and export to CSV. To accomplish this with the adobe interface, use CTRL+SHIFT+F to get a search window. After you have searched a keyword, there is an option to export these results. This is where the page numbers come from. The excel data is then arranged for AHK script to read and make decisions on what pages to delete. Do you have any knowledge on how to generate this report without doing the search manually?

Thanks again! :)


EDIT:
I'm reading the Search properties here; https://help.adobe.com/livedocs/acrobat ... earch.html

Wondering if SearchExecuteQuery() might be a possibility? The only thing is it displays the results in the search window when done.
FanaticGuru wrote:
Vh_ wrote:
The last thing i'd like to look into is setting the value of a fillable field on a PDF, perhaps better suited for another thread but I thought i'd ask anyway :)
Here are two ways to go about working with fields in a PDF.

Code: Select all

F12::
	AFormAut := ComObjCreate("AFormAut.App")
	for Field in AFormAut.Fields
	{
		fNum := A_Index - 1
		fName := Field.Name
		fValue := Field.Value
		MsgBox % "Field Number = " fNum "`nField Name = " fName "`nField Value = " fValue
	}
	AFormAut.Fields("Your Name").Value := "Fanatic Guru"
return

F11::
	App := ComObjCreate("AcroExch.App")
	AVDoc := App.GetActiveDoc()
	PDDoc := AVDoc.GetPDDoc()
	JSO	:= PDDoc.GetJSObject
	Loop % JSO.NumFields
	{
		fNum := A_Index - 1
		fName := JSO.GetNthFieldName(fNum)
		fValue := JSO.GetField(fName).Value
		MsgBox % "Field Number = " fNum "`nField Name = " fName "`nField Value = " fValue
	}
	JSO.GetField("Your Name").Value := "Fanatic Guru"
return
Both of these work on the current active PDF.

The first uses Acrobat more directly while the second taps into the JavaScript abilities of Acrobat.

FG
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Delete PDF Pages through Adobe COM

09 May 2018, 19:09

Vh_ wrote:My next goal is to achieve is to do the advanced search and export to CSV. To accomplish this with the adobe interface, use CTRL+SHIFT+F to get a search window. After you have searched a keyword, there is an option to export these results. This is where the page numbers come from. The excel data is then arranged for AHK script to read and make decisions on what pages to delete. Do you have any knowledge on how to generate this report without doing the search manually?
I don't know how to generate that report without basically just automating the dialog. I don't know how to just do the same thing without going through the dialog. I believe that is a plugin and could possibly be interfaced with through DDE without going through the dialog but I don't know all the specifics.

On another note I tried to find the page numbers of pages that contain a search word.

Code: Select all

F11::
	Search := "Word"
	Found := {}
	App := ComObjCreate("AcroExch.App")
	AVDoc := App.GetActiveDoc()
	PDDoc := AVDoc.GetPDDoc()
	JSO	:= PDDoc.GetJSObject
	MsgBox % JSO.NumPages
	Loop % JSO.NumPages
	{
		p := A_Index-1
		Loop % JSO.GetPageNumWords(p)
		{
			w := A_Index-1
			Word := JSO.GetPageNthWord(p, w)
			if InStr(Word, Search)
			{
				if Found[p]
					Found[p] := Found[p] + 1
				else
					Found[p] := 1
			}
		}
	}
	Display := "Zero-Indexed Pages`n"
	for k, v in Found
		Display .= "Page = " k "  `tFound = " v "`n"
	MsgBox % Display
return
This will find every page that contains "Word" in a PDF but it is pretty slow. It basically loops through every word in a PDF and checks it.

Wrote as an experiment and just putting it out there for general knowledge.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: Delete PDF Pages through Adobe COM

14 May 2018, 12:01

FanaticGuru,

That did return results but as you said, the result is not so fast. This is the case with the manual interface search method as well. I think I will stick with that method for the time being.

Thanks again!
Vh
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: Delete PDF Pages through Adobe COM

24 May 2018, 08:52

I'm looking to insert a blank page between each page in a PDF. I have an idea, but not sure on how to specify where the blank page should be placed.

The structure of my idea is having a PDF with one blank page and insert that page in the file I want to have blank pages in. Any idea on how to do this?

Thanks,
Vh
FanaticGuru wrote: FG
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Delete PDF Pages through Adobe COM

24 May 2018, 13:27

Vh_ wrote:I'm looking to insert a blank page between each page in a PDF. I have an idea, but not sure on how to specify where the blank page should be placed.

The structure of my idea is having a PDF with one blank page and insert that page in the file I want to have blank pages in. Any idea on how to do this?
The code from above post has the command for inserting pages. The first parameter is the location to insert.

Code: Select all

; InsertPages(nInsertPageAfter, iPDDocSource, nStartPage, nNumPages, bBookmarks)
PDDoc_Main.InsertPages(1, PDDoc_Blank, 0, 1, 0) ; index-0, add first page from PDDoc_Blank after the second page of PDDoc_Main, without bookmarks
Just need to do some math to get the right insert point and remember that the pages are index-0 meaning the first page is referenced as 0.

You can do it with JavaScript without having a blank template document.

Code: Select all

F12::
	App := ComObjCreate("AcroExch.App")
	AVDoc := App.GetActiveDoc()
	PDDoc := AVDoc.GetPDDoc()
	JSO	:= PDDoc.GetJSObject
	JSO.newPage(1) ; add page after 1st page
return
This will add a blank page after the 1st page of the active document.

newPage has a 2nd and 3rd parameter for setting width and height if you need something besides the defaults.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: Delete PDF Pages through Adobe COM

26 Apr 2019, 09:14

@FanaticGuru
You came to mind for yet another challenge a fellow AHK member and I have been trying to conquer. See the attachment.

Wondering if there is a way to connect to "adobe generated fields". For example, the bottom right is XX-XXX-XXXX. Need to edit that field and set a value. Can we do this though COM?

Any help on this is appreciated!

Thanks,
Vh_
Attachments

[The extension pdf has been deactivated and can no longer be displayed.]


Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: garry, marypoppins_1, mikeyww, OrangeCat, RussF and 155 guests