How do I install pyuno in my python package?
I have windows 11 , Libre office 7.5.1.2 , and I run Python 3.9 fron Spyder (Anaconda).
I want to open all the pdf files in a folder and run my internal macro on them and then save the files from Python . Here is the Python code i have thus far:
import os
import subprocess
import time
import pyuno
pdf_folder = "C:\Work_offline\Junk"
# Get a list of all PDF files in the folder
pdf_files = [os.path.join(pdf_folder, f) for f in os.listdir(pdf_folder) if f.endswith(".pdf")]
# Loop over the PDF files and open them in Libre Draw
for pdf_file in pdf_files:
cmd = ["C:\Program Files\LibreOffice\program\soffice.exe", "--draw", pdf_file]
subprocess.run(cmd)
# Wait for Libre Draw to start and load the document
time.sleep(5)
# Connect to Libre Draw and run the Macro1 macro
localContext = pyuno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
# Get the document that was just opened
component = desktop.getCurrentComponent()
# Run the Macro1 macro
oScriptProvider = component.getScriptProvider()
oScript = oScriptProvider.getScript("vnd.sun.star.script:Standard.Module1.DeleteLastShape?language=Basic&location=application")
oScript.invoke(())