该问题与使用 LibreOffice 无头转换器自动转换上传的文件有关。出现此错误:
LibreOffice 7 fatal error - Application cannot be started
Ubuntu 版本:21.04
我尝试过的:
从 Azure Blob 存储获取文件,
将其放入 BASE_DIR/Input_file 中,
使用我通过子进程运行的 Linux 命令将其转换为 PDF,
将其放入 BASE_DIR/Output_file 文件夹中。
下面是我的代码:
我正在以这种方式将 LibreOffice 安装到 docker
RUN apt-get update \
&& ACCEPT_EULA=Y apt-get -y install LibreOffice
主要逻辑:
blob_client = container_client.get_blob_client(f"Folder_with_reports/")
with open(os.path.join(BASE_DIR, f"input_files/{filename}"), "wb") as source_file:
source_file.write(data)
source_file = os.path.join(BASE_DIR, f"input_files/{filename}") # original docs here
output_folder = os.path.join(BASE_DIR, "output_files") # pdf files will be here
# assign the command of converting files through LibreOffice
command = rf"lowriter --headless --convert-to pdf {source_file} --outdir {output_folder}"
# running the command
subprocess.run(command, shell=True)
# reading the file and uploading it back to Azure Storage
with open(os.path.join(BASE_DIR, f"output_files/MyFile.pdf"), "rb") as outp_file:
outp_data = outp_file.read()
blob_name_ = f"test"
container_client.upload_blob(name = blob_name_ ,data = outp_data, blob_type="BlockBlob")
我应该安装吗lowriter代替自由办公室?对于这种操作可以使用 BASE_DIR 吗?我将不胜感激任何建议。