Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
MinerU
Commits
039f8cbf
"models/vscode:/vscode.git/clone" did not exist on "9c4cd06df936aede6c3a6dafffb8679242d548f2"
Commit
039f8cbf
authored
Apr 14, 2025
by
Doge2077
Browse files
feat:add advice on LibreOffice installing
parent
82a4376d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
5 deletions
+49
-5
magic_pdf/utils/office_to_pdf.py
magic_pdf/utils/office_to_pdf.py
+49
-5
No files found.
magic_pdf/utils/office_to_pdf.py
View file @
039f8cbf
...
...
@@ -2,6 +2,7 @@ import os
import
subprocess
import
platform
from
pathlib
import
Path
import
shutil
class
ConvertToPdfError
(
Exception
):
...
...
@@ -43,19 +44,62 @@ def check_fonts_installed():
def
get_soffice_command
():
"""Return the path to LibreOffice's soffice executable depending on the platform."""
if
platform
.
system
()
==
'Windows'
:
system_type
=
platform
.
system
()
# First check if soffice is in PATH
soffice_path
=
shutil
.
which
(
'soffice'
)
if
soffice_path
:
return
soffice_path
if
system_type
==
'Windows'
:
# Check common installation paths
possible_paths
=
[
Path
(
"C:/Program Files/LibreOffice/program/soffice.exe"
),
Path
(
"C:/Program Files (x86)/LibreOffice/program/soffice.exe"
)
Path
(
os
.
environ
.
get
(
'PROGRAMFILES'
,
'C:/Program Files'
))
/
'LibreOffice/program/soffice.exe'
,
Path
(
os
.
environ
.
get
(
'PROGRAMFILES(X86)'
,
'C:/Program Files (x86)'
))
/
'LibreOffice/program/soffice.exe'
,
Path
(
'C:/Program Files/LibreOffice/program/soffice.exe'
),
Path
(
'C:/Program Files (x86)/LibreOffice/program/soffice.exe'
)
]
# Check other drives for windows
for
drive
in
[
'C:'
,
'D:'
,
'E:'
,
'F:'
,
'G:'
,
'H:'
]:
possible_paths
.
append
(
Path
(
f
"
{
drive
}
/LibreOffice/program/soffice.exe"
))
for
path
in
possible_paths
:
if
path
.
exists
():
return
str
(
path
)
raise
ConvertToPdfError
(
"LibreOffice not found. Please install LibreOffice and ensure soffice.exe is located in a standard path."
"LibreOffice not found. Please install LibreOffice from https://www.libreoffice.org/ "
"or ensure soffice.exe is in your PATH environment variable."
)
else
:
return
'soffice'
# Assume it's in PATH on Linux/macOS
# For Linux/macOS, provide installation instructions if not found
try
:
# Try to find soffice in standard locations
possible_paths
=
[
'/usr/bin/soffice'
,
'/usr/local/bin/soffice'
,
'/opt/libreoffice/program/soffice'
,
'/Applications/LibreOffice.app/Contents/MacOS/soffice'
]
for
path
in
possible_paths
:
if
os
.
path
.
exists
(
path
):
return
path
# Last attempt with which
soffice_path
=
shutil
.
which
(
'soffice'
)
if
soffice_path
:
return
soffice_path
raise
ConvertToPdfError
(
"LibreOffice not found. Please install it:
\n
"
" - Ubuntu/Debian: sudo apt-get install libreoffice
\n
"
" - CentOS/RHEL: sudo yum install libreoffice
\n
"
" - macOS: brew install libreoffice or download from https://www.libreoffice.org/
\n
"
" - Or ensure soffice is in your PATH environment variable."
)
except
Exception
as
e
:
raise
ConvertToPdfError
(
f
"Error locating LibreOffice:
{
str
(
e
)
}
"
)
def
convert_file_to_pdf
(
input_path
,
output_dir
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment