Код: Выделить всё
$docx_filename = "/var/www/editeur/docx/".$file1
$command5 = "python3 conv_docx_pdf.py \"$docx_filename\"";
$output = shell_exec($command5);
Код: Выделить всё
import subprocess
import os
import sys
def docx_to_pdf(input_file):
# Get the file name without extension
file_name, _ = os.path.splitext(input_file)
# Construct the output file path with .pdf extension
output_file = file_name + ".pdf"
# Run unoconv to convert DOCX to PDF
subprocess.run(["unoconv", "-f", "pdf", input_file])
return output_file
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py ")
sys.exit(1)
input_file = sys.argv[1] # Get the input file from command-line argument
output_file = docx_to_pdf(input_file)
print("Output PDF:", output_file)
Код: Выделить всё
python3 conv_docx_pdf.py filename1.docxправа на папку docx:
drwxr-xr-x 2 www -data www-data 4096 26 марта 12:58 docx
права для файла $file1
-rw-r--r-- 1 www-data www-data 11738 26 марта 11:45 status29024.docx
У меня есть другие программы Python (которые не используют подпроцесс), которые работают нормально при вызове из php.
Любая помощь приветствуется.
Подробнее здесь: https://stackoverflow.com/questions/782 ... d-from-php
Мобильная версия