Category: default

How to use LibreOffice and unoserver to convert docx to pdf in Ubuntu/Debian

  1. Install LibreOffice and unoserver with the following commands:
    apt install libreoffice python3 python3-pip
    pip install unoserver
  2. Make sure the environment is ok:
    wget -O find_uno.py https://gist.githubusercontent.com/regebro/036da022dc7d5241a0ee97efdf1458eb/raw/find_uno.py
    python3 find_uno.py
  3. Start unoserver and take a conversion in diffrerent command line prompt:
    python3 -m unoserver.server
    python3 -m unoserver.converter --convert-to pdf my.docx my.pdf
  4. If you encounter the font problem, you should add windows fonts to Linux with the following steps.
    1. Copy all fonts files under C:\Windows\Fonts
    2. Remove the .fon files
    3. Copy the font files to Linux and paste the files in /usr/share/fonts/win/. and you should create win directory by yourself.
    4. Update the font cache with the following commands in /usr/share/fonts/win/ :
      mkfontscale
      mkfontdir
      fc-cache

      If you cannot find the commands, run

      apt-get install xfonts-utils
    5. You can also check the font status via fc-list
  5. Create a system service for unoserver in /etc/systemd/system/unoserver.service:
    [Unit]
    Description=unoserver
    After=network.target
    
    [Install]
    WantedBy=multi-user.target
    
    [Service]
    Type=simple
    User=root
    Group=root
    ExecStart=/usr/local/bin/unoserver
    Environment=PYTHONUNBUFFERED=true
    Restart=on-failure
    RestartSec=3

    You should also use systemctl daemon-reload to take effect. And if you want to make the service on startup, run systemctl enable daemon-reload

How to backup lxc and restore in QNAP NAS

Backup:

cd /var/lib/lxc/${lxc_name}/
tar --numeric-owner -czvf ${lxc_name}.tar.gz ./*

Restore:

mkdir/var/lib/lxc/${lxc_name}/
cd/var/lib/lxc/${lxc_name}/
tar --numeric-owner -xzvf ${lxc_name}.tar.gz .

${lxc_name} should be your lxc`s name.