在 Ubuntu 18.10、Ubuntu 18.04 LTS 和 Ubuntu GNOME 16.04 LTS 下,我使用了Nautilus - 适用于 Ms Office 文档的缩略图成功生成 Microsoft Office ( .doc
、.docx
等.pptx
) 文档的缩略图。
现在,在 Ubuntu 20.04 中,这不再起作用。我查看了脚本msoffice-thumbnailer
,我认为问题与/tmp
目录中生成的错误路径有关。
请帮忙!
答案1
好的,我设法通过修改在 Ubuntu 22 中获取我的 MS Office 缩略图bwrap
,/usr/local/bin
如下所示:
#!/usr/bin/env bash
# bwrap wrapper to correct nautilus 3.26.4+ bug for external thumbnailers under debian based distros
# * add --ro-bind needed by imagemagick tools
# * replaces --symlink calls with equivalent --ro-bind calls
# intialise parameters array
ARR_PARAM=( )
ARR_PARAM=( "${ARR_PARAM[@]}" "--bind" "/" "/" )
# add read only access to /usr/local, /var/lib, /var/cache and /etc
#[ -d "/usr/local" ] && ARR_PARAM=( "${ARR_PARAM[@]}" "--ro-bind" "/usr/local" "/usr/local" )
#[ -d "/var/lib" ] && ARR_PARAM=( "${ARR_PARAM[@]}" "--ro-bind" "/var/lib" "/var/lib" )
#[ -d "/var/cache" ] && ARR_PARAM=( "${ARR_PARAM[@]}" "--ro-bind" "/var/cache" "/var/cache" )
#[ -d "/etc" ] && ARR_PARAM=( "${ARR_PARAM[@]}" "--ro-bind" "/etc" "/etc" )
# if exists, enable $TMPDIR
#[ -n "${TMPDIR}" ] && [ -d "${TMPDIR}" ] && ARR_PARAM=( "${ARR_PARAM[@]}" "--bind" "${TMPDIR}" "${TMPDIR}" )
# loop thru original parameters
while test $# -gt 0
do
case "$1" in
# --symlink : convert to --ro-bind
"--symlink") shift; shift; ARR_PARAM=( "${ARR_PARAM[@]}" "--bind" "$1" "$1" ); shift; ;;
# others : add parameter
*) ARR_PARAM=( "${ARR_PARAM[@]}" "$1" ); shift; ;;
esac
done
# call original bwrap
/usr/bin/bwrap "${ARR_PARAM[@]}"
以及msoffice-thumbnailer
在/usr/local/sbin
:
#!/usr/bin/env bash
# ---------------------------------------------------
# Thumbnailer for Ms Office documents
#
# Procedure :
# http://bernaerts.dyndns.org/linux/76-gnome/325-gnome-shell-generate-msoffice-thumbnail-nautilus
# Depends on :
# * libreoffice
# * mimetype (libfile-mimeinfo-perl package)
# * pbmmake, pngtopnm, pnmtopng, pnmscalefixed and pnmcomp (netpbm package)
# Parameters :
# $1 - path of office file
# $2 - path of generated thumbnail
# $3 - height of thumbnail in pixels
# Revision history :
# 11/11/2014, V1.0 - Creation by N. Bernaerts
# 15/11/2014, V2.0 - Change to URI and GVFS to handle thumbnails on network shares
# 31/07/2015, V2.1 - More robust unoconv command line (thanks to Vaderqk)
# 07/10/2017, V2.2 - Speedup with netpbm tools
# 10/03/2018, V3.0 - Switch from unoconv to libreoffice in headless mode
# 15/03/2018, V3.1 - Handle libreoffice and soffice binaries
# 09/12/2018, V3.2 - Rework for bubblewrap compatibility (thanks to Li Chong)
# ---------------------------------------------------
# check libreoffice availability (binary can be either libreoffice or soffice)
CMD_OFFICE="libreoffice"
command -v "${CMD_OFFICE}" >/dev/null 2>&1 || CMD_OFFICE="soffice"
command -v "${CMD_OFFICE}" >/dev/null 2>&1 || { echo "[error] libreoffice missing"; exit 1; }
# check tools availability
command -v pbmmake >/dev/null 2>&1 || { echo "[error] pbmmake missing"; exit 1; }
command -v pngtopnm >/dev/null 2>&1 || { echo "[error] pngtopnm missing"; exit 1; }
command -v pnmscalefixed >/dev/null 2>&1 || { echo "[error] pnmscalefixed missing"; exit 1; }
command -v pnmcomp >/dev/null 2>&1 || { echo "[error] pnmcomp missing"; exit 1; }
command -v pnmtopng >/dev/null 2>&1 || { echo "[error] pnmtopng missing"; exit 1; }
cp: cannot stat
# check params
[ "$3" = "" ] && { echo "[error] 3 params are needed : file file-thumb thumb-size"; exit 1; }
# get parameters
FILE_LOCAL="$1"
FILE_NAME=$(basename "${FILE_LOCAL}")
FILE_THUMB="$2"
SIZE="$3"
cp "$FILE_LOCAL" "$HOME/temp"
FILE_INPUT_SOFFICE="$HOME/temp/$FILE_NAME"
# set working path
PATH_SYSTEM="/usr/local/sbin/msoffice-thumbnailer.res"
[ ! -d "${PATH_SYSTEM}" ] && { echo "[error] directory ${PATH_SYSTEM} missing"; exit 1; }
# generate temporary files and directory
TMP_DIR=$(mktemp -t -d "thumb-ms-XXXXXXXX")
TMP_PNM="${TMP_DIR}/original.pnm"
TMP_THUMB="${TMP_DIR}/thumbnail.pnm"
# get the file mime type (application/msword, ...)
MIMETYPE=$(mimetype -b "${FILE_LOCAL}")
# determine icon type according to mime type
case ${MIMETYPE} in
# text
"application/msword" | \
"application/vnd.ms-word" | \
"application/vnd.openxmlformats-officedocument.wordprocessingml.document" | \
"application/wps-office.doc" | \
"application/wps-office.docx" )
DOC_TYPE="odt"
;;
# spreadsheet
"application/vnd.ms-excel" | \
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | \
"application/vnd.openxmlformats-officedocument.spreadsheetml.template" | \
"application/wps-office.xls" | \
"application/wps-office.xlsx" )
DOC_TYPE="ods"
;;
# presentation
"application/vnd.ms-powerpoint" | \
"application/vnd.openxmlformats-officedocument.presentationml.presentation" | \
"application/vnd.openxmlformats-officedocument.presentationml.template" | \
"application/vnd.openxmlformats-officedocument.presentationml.slideshow" | \
"application/wps-office.ppt" | \
"application/wps-office.pptx" )
DOC_TYPE="odp"
;;
* )
;;
esac
# get document tag and mask
DOC_TAG="${PATH_SYSTEM}/msoffice-${DOC_TYPE}.pnm"
DOC_ALPHA="${PATH_SYSTEM}/msoffice-${DOC_TYPE}-alpha.pnm"
# convert first page to PNG
#${CMD_OFFICE} "-env:UserInstallation=file://${TMP_DIR}" --headless --convert-to png --outdir "${TMP_DIR}" "${FILE_LOCAL}"
${CMD_OFFICE} "-env:UserInstallation=file://${TMP_DIR}" --headless --convert-to png --outdir "${TMP_DIR}" "${FILE_INPUT_SOFFICE}" 2>&1
# convert PNG to PNM
FILE_NAME=$(basename "${FILE_LOCAL}")
FILE_NAME="${FILE_NAME%.*}"
pngtopnm "${TMP_DIR}/${FILE_NAME}.png" | pnmscalefixed -xysize 256 256 - > "${TMP_PNM}" 2>&1
# generate 256x256 thumbnail with masks
pbmmake -white 188 256 | pnmcomp -xoff 2 -yoff=52 "${TMP_PNM}" - | pnmcomp -align left -valign top -alpha "${DOC_ALPHA}" "${DOC_TAG}" - > "${TMP_THUMB}" 2>&1
# downscale to final size and convert to png
pnmscalefixed -xysize ${SIZE} ${SIZE} "${TMP_THUMB}" | pnmtopng -downscale - > "${FILE_THUMB}" 2>&1
# remove temporary directory
rm -r "${TMP_DIR}"
rm -r $HOME/temp/*
请注意,最后一行的内容$HOME/temp
被删除了。
最后在/usr/share/thumbnailers/msoffice.thumbnailer
:
[Thumbnailer Entry]
Exec=/bin/bash /usr/local/sbin/msoffice-thumbnailer %i %o %s
MimeType=application/msword;application/vnd.ms-word;application/vnd.openxmlformats-officedocument.wordprocessingml.document;application/vnd.ms-excel;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;application/vnd.openxmlformats-officedocument.spreadsheetml.template;application/vnd.ms-powerpoint;application/vnd.openxmlformats-officedocument.presentationml.presentation;application/vnd.openxmlformats-officedocument.presentationml.template;application/vnd.openxmlformats-officedocument.presentationml.slideshow;application/ms-office;application/wps-office.xlsx;application/wps-office.xls;application/wps-office.ppt;application/wps-office.pptx;application/wps-office.doc;application/wps-office.docx;
希望能帮助到你!