[Python] How to run a macro before converting a file to PDF?

Discussão em 'Python' iniciado por Stack, Fevereiro 14, 2025.

  1. Stack

    Stack Membro Participativo

    I need to convert a .txt file (unicode) file to PDF using libreoffice using AWS lamabda function. It can be achieved using the code found here...

    https://github.com/fritzpaz/lambda-libre-office/blob/main/main.py#L19

    The code is working as expected. And this line is the most important.

    result = subprocess.run(['/opt/libreoffice7.5/program/soffice', '--headless', '--nologo', '--nodefault', '--nofirststartwizard', '--convert-to', 'pdf', file, '--outdir', '/tmp'], capture_output=True)


    I need to run a macro before converting the file to PDF. So I added this line just before the one mentioned above.

    macro_result = subprocess.run(
    ["/opt/libreoffice7.5/program/soffice", "--headless", "--invisible", "--norestore",
    f"macro:///StyleLibrary.Module1.myStyleMacro2({file})"],
    check=False, capture_output=True


    This line gets executed and changes the file as indicated by timestamp of the file. But the contents of the macro are not actually applied to the text inside the file. I have made sure that the macro is installed through extension. And the macro is working as expected and there is no problem with the macro code. I must be missing something in subprocess.run method.

    Continue reading...

Compartilhe esta Página