I am getting the error :
javaldx failed!
Warning: failed to read path from javaldx
(process:34129): dconf-CRITICAL **: 08:18:31.604: unable to create directory ‘/var/www/.cache/dconf’: Permission denied. dconf will not work properly.
LibreOffice 7.5 - Fatal Error: The application cannot be started.
User installation could not be completed.
[Wed Mar 13 08:18:31.626422 2024] [wsgi:error] [pid 34037:tid 140694461216448] [remote 103.211.54.213:60854] [ERROR] Internal Server Error: /word_to_pdf
Here is my code :
if request.method == 'POST' and request.FILES.get('word_file'):
word_file = request.FILES['word_file']
try:
# Create a temporary directory to store the uploaded files
temp_dir = tempfile.mkdtemp()
# Construct the file path for the uploaded Word file
word_file_path = os.path.join(temp_dir, word_file.name)
# Write the uploaded Word file to the temporary file path
with open(word_file_path, 'wb') as f:
for chunk in word_file.chunks():
f.write(chunk)
# Specify the directory for the temporary PDF file
temporary_pdf_dir = os.path.join(settings.MEDIA_ROOT, 'temporary_pdfs')
# libreoffice_path = r'C:\\Program Files\\LibreOffice\\program\\soffice.exe'
# Adjust the path accordingly
subprocess.run(['libreoffice', "--headless", '--convert-to', 'pdf', '--outdir', temporary_pdf_dir, word_file_path])
# Get the generated PDF file path
temp_pdf_file_path = os.path.join(temporary_pdf_dir, word_file.name.split('.')[0] + '.pdf')
# Save the converted PDF content to the database
with open(temp_pdf_file_path, 'rb') as f:
temporary_pdf = TemporaryPDF.objects.create()
temporary_pdf.pdf_file.save('wordtopdf.pdf', ContentFile(f.read()))
# Delete temporary files
os.remove(word_file_path)
os.remove(temp_pdf_file_path)
# Render the template to download the PDF
return render(request, 'pdftools/download_pdfs.html', {'pdf_file': temporary_pdf})
except Exception as e:
return HttpResponse(f"Error during conversion: {e}", status=500)
else:
return render(request, 'pdftools/word_to_pdf.html') ```