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?
Manipulate PDF
-
- Posts: 98
- Joined: 23 Apr 2023, 13:03
Re: Manipulate PDF
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.
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.
-
- Posts: 98
- Joined: 23 Apr 2023, 13:03
Re: Manipulate PDF
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
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
Re: Manipulate PDF
If you craft a command line that would work in a Windows batch file, you can then use 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.
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.
Re: Manipulate PDF
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.
in AHK you just need to use an external app or libraries, so you can use RUN ,COM ,DLL command.
Re: Manipulate PDF
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()
-
- Posts: 98
- Joined: 23 Apr 2023, 13:03
Re: Manipulate PDF
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.
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.
-
- Posts: 32
- Joined: 13 Aug 2021, 13:34
Re: Manipulate PDF
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).
-
- Posts: 98
- Joined: 23 Apr 2023, 13:03
Re: Manipulate PDF
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.
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.
Re: Manipulate PDF
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.Felix Siano wrote: ↑30 Apr 2024, 13:18I 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.
Re: Manipulate PDF
If you can do AHK, you would be able to learn Python quickly. Are the same concepts, just with different keywords. As for your problem - I was using pdfcpu as commandline from AHK script. It has watermark function, which may be of interest for you.
https://pdfcpu.io/core/watermark#examples
Part of my script, which merges pdfs:
https://pdfcpu.io/core/watermark#examples
Part of my script, which merges pdfs:
Code: Select all
app := "\\path\to\pdfcpu\pdfcpu.exe " ;with space at the end
Loop Files, folder_path "*.pdf"
{
file_paths.Push(A_LoopFileFullPath) ;adds file paths to an array for a given counter of files
if file_paths.Length >= file_count[]{
break
}
}
for index, Value in file_paths ;converts the array into string, delimited by space, as required for pdfcpu
{
file_path_txt .= Value . " "
}
RunWait app " merge " folder_path today "\" filename " " file_path_txt ;executing commandline pdfcpu
-
- Posts: 98
- Joined: 23 Apr 2023, 13:03
Re: Manipulate PDF
Perfect!
I will take a look...
I downloaded pdfcpu.exe, do I just need to put the script.ahk in the same folder where pdfcpu.exe is?
I will take a look...
I downloaded pdfcpu.exe, do I just need to put the script.ahk in the same folder where pdfcpu.exe is?
-
- Posts: 98
- Joined: 23 Apr 2023, 13:03
Re: Manipulate PDF
What am I doing wrong in ~a&2?
No ~a & 1 works
No ~a & 1 works
Code: Select all
~a & 1::
{
RunWait "C:\Users\siano\Desktop\pdfcpu.exe" merge "C:\Users\siano\Desktop\Junto.pdf" "C:\Users\siano\Desktop\NOTAS\*.pdf"
}
~a & 2::
{
RunWait "C:\Users\siano\Desktop\pdfcpu.exe" watermark add -mode pdf -- "C:\Users\siano\Desktop\1.pdf:1" "C:\Users\siano\Desktop\10.pdf" "C:\Users\siano\Desktop\THEEND.pdf"
}
Re: Manipulate PDF
The first one isn’t correct either unless you’re running it with v1. Do you see why?
Re: Manipulate PDF
You are running a command line, so you need to send a string to it. That means all the commands shold also be in the string, all delimited by spaces.
Re: Manipulate PDF
arguments should with quotesFelix Siano wrote: ↑17 May 2024, 22:41What am I doing wrong in ~a&2?
No ~a & 1 works
Code: Select all
~a & 1:: { RunWait "C:\Users\siano\Desktop\pdfcpu.exe" merge "C:\Users\siano\Desktop\Junto.pdf" "C:\Users\siano\Desktop\NOTAS\*.pdf" } ~a & 2:: { RunWait "C:\Users\siano\Desktop\pdfcpu.exe" watermark add -mode pdf -- "C:\Users\siano\Desktop\1.pdf:1" "C:\Users\siano\Desktop\10.pdf" "C:\Users\siano\Desktop\THEEND.pdf" }
this example
Code: Select all
Run('"' AHK__python_Musicplayer_py__path '"' ' "' path '"' ' "' enableLoop '"' ' "' loopTime '"' , , hide__Opt ,&musicPlayer__PID )