Manipulate PDF

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Felix Siano
Posts: 88
Joined: 23 Apr 2023, 13:03

Manipulate PDF

Post by Felix Siano » 27 Apr 2024, 19:15

Is it possible to manipulate pdf files with AutoHotkey?
Merge two PDF files from a folder and also merge two PDFs on the same page, like one page on top of the other.
possible?

User avatar
mikeyww
Posts: 27133
Joined: 09 Sep 2014, 18:38

Re: Manipulate PDF

Post by mikeyww » 27 Apr 2024, 19:19

Hello,

You might want to search the forum for some of the existing posts about PDF that show techniques. You can also use other command-line tools such as xpdf and pdftk.

Felix Siano
Posts: 88
Joined: 23 Apr 2023, 13:03

Re: Manipulate PDF

Post by Felix Siano » 29 Apr 2024, 23:06

I'm looking for. Reading, trying to understand!
I found a post (I think it was yours) using sumatraPDF
Could you help me use these commands in ahk?
Two options that would help me with my work are printing a PDF file from a folder and printing using the "duplex" printing that is in the documentation. Follow Link below:
https://www.sumatrapdfreader.org/docs/Command-line-arguments

User avatar
mikeyww
Posts: 27133
Joined: 09 Sep 2014, 18:38

Re: Manipulate PDF

Post by mikeyww » 30 Apr 2024, 06:13

If you craft a command line that would work in a Windows batch file, you can then use :arrow: Run to execute the same command line.

Here is maybe a hidden gem, too. MiKTeX is a free program library that you can install as portable. It contains a program called pdfunite.exe that you can use to join or merge your PDF files easily. You can write an AHK script that uses a GUI to select files to merge. Run can then call pdfunite.exe to merge them.

User avatar
xMaxrayx
Posts: 184
Joined: 06 Dec 2022, 02:56
Contact:

Re: Manipulate PDF

Post by xMaxrayx » 30 Apr 2024, 10:15

if you have heavy work and not merge you better use Python if you want an easier approach because of its library,

in AHK you just need to use an external app or libraries, so you can use RUN ,COM ,DLL command.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

Jasonosaj
Posts: 53
Joined: 02 Feb 2022, 15:02
Location: California

Re: Manipulate PDF

Post by Jasonosaj » 30 Apr 2024, 10:35

xMaxrayx wrote:
30 Apr 2024, 10:15
if you have heavy work and not merge you better use Python if you want an easier approach because of its library,

in AHK you just need to use an external app or libraries, so you can use RUN ,COM ,DLL command.
I use the following to diff PDFs:



import subprocess
import sys
from tkinter import filedialog, Tk, messagebox

def select_files():
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
file_paths = filedialog.askopenfilenames() # show an "Open" dialog box and return the path to the selected file
return file_paths

def run_diff_pdf(file1, file2):
command = f'diff-pdf /m /g --view "{file1}" "{file2}"'
subprocess.run(command, shell=True)

def main():
if len(sys.argv) == 3: # if two files are passed as arguments
file1 = sys.argv[1]
file2 = sys.argv[2]
else: # if no files or only one file is passed as argument
files = select_files()
if len(files) != 2:
messagebox.showerror("Error", "Please select exactly two files.")
return
file1, file2 = files

run_diff_pdf(file1, file2)

if __name__ == "__main__":
main()


Felix Siano
Posts: 88
Joined: 23 Apr 2023, 13:03

Re: Manipulate PDF

Post by Felix Siano » 30 Apr 2024, 13:18

I did it with .ahk and using Sumatrapdf to print and pdftk to merge the PDFs.
Thank you for your help. But I don't understand Python very well.
The good thing about ahk is that it is possible to compile to .exe, I don't know if it is possible in Python.
The only thing missing was a good option to join the two pages of a PDF, as if it were a stamp. I need to remove the printed page from the printer and place it to be printed in the same previous print.

metallizer
Posts: 32
Joined: 13 Aug 2021, 13:34

Re: Manipulate PDF

Post by metallizer » 02 May 2024, 08:14

If you have acrobat pro (not sure about non pro) you can use ComObject('AcroExch.App') for automation (Link). There is a method under AcroExch.PDDoc called InsertPages which inserts the specified pages from the source document after the indicated page within the current document (essentially merging two pdf).

Felix Siano
Posts: 88
Joined: 23 Apr 2023, 13:03

Re: Manipulate PDF

Post by Felix Siano » 02 May 2024, 11:32

Thank you for your help!
I just managed to do it on script.vbs I couldn't get it in .ahk. But it adds the first page does not mix one file in the other. The final PDF is the same as the PDF being mixed. is not accepting one page mixed in the other. At least I couldn't have it.

User avatar
xMaxrayx
Posts: 184
Joined: 06 Dec 2022, 02:56
Contact:

Re: Manipulate PDF

Post by xMaxrayx » 07 May 2024, 03:40

Felix Siano wrote:
30 Apr 2024, 13:18
I did it with .ahk and using Sumatrapdf to print and pdftk to merge the PDFs.
Thank you for your help. But I don't understand Python very well.
The good thing about ahk is that it is possible to compile to .exe, I don't know if it is possible in Python.
The only thing missing was a good option to join the two pages of a PDF, as if it were a stamp. I need to remove the printed page from the printer and place it to be printed in the same previous print.
you can actually convert python to exe even you can do virtual environment to have all dependency packages but no one do it because it will make it bigger than it should be ,the good with python it has a lot of libraries but yeah I understand it's annoying if you didn't learn the language but I think it's worth it.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

Post Reply

Return to “Ask for Help (v2)”