2

I installed a node server in the docker and am using Libre Office. It works normally in a Windows environment, but in a Docker environment, the characters are broken and the cause is unknown. Below is an image of the docker file and broken letters.

FROM node:12-alpine

WORKDIR "/app"

COPY package*.json ./

RUN apk update && apk add libreoffice

# RUN npm install
RUN npm ci --only=production

COPY . .

CMD ["npm", "start"]

convert,

const libre = require(`libreoffice-convert`)

// Read file
        const file = fs.readFileSync(enterPath);
        // Convert it to pdf format with undefined filter (see Libreoffice doc about filter)
        const status = await new Promise((resolve, reject) => {
            libre.convert(file, pdfExtend, undefined, (err, done) => {
                if (err) {
                    console.log(err)
                    reject(err)
                }
                // Here in done you have pdf file which you can save or transfer in another stream
                fs.writeFileSync(outputPath, done);
                resolve(200)
            });
        })

result,

enter image description here

enter image description here

help me

yahoo2344
  • 83
  • 10

1 Answers1

7

I think there are missing fonts in Alpine Linux, and there are two workarounds that come to mind right now. (docker image: node:12-alpine)

  1. change image
  • There is no guarantee that it will work
FROM node:12-slim
  1. install fonts
FROM node:12-alpine

WORKDIR "/app"

COPY package*.json ./

RUN apk update && apk add libreoffice
RUN apk add --no-cache msttcorefonts-installer fontconfig
RUN update-ms-fonts

# Google fonts
RUN wget https://github.com/google/fonts/archive/main.tar.gz -O gf.tar.gz --no-check-certificate
RUN tar -xf gf.tar.gz
RUN mkdir -p /usr/share/fonts/truetype/google-fonts
RUN find $PWD/fonts-main/ -name "*.ttf" -exec install -m644 {} /usr/share/fonts/truetype/google-fonts/ \; || return 1
RUN rm -f gf.tar.gz
RUN fc-cache -f && rm -rf /var/cache/*

# RUN npm install
RUN npm ci --only=production

COPY . .

CMD ["npm", "start"]
myeongkil kim
  • 2,465
  • 4
  • 16
  • 22
  • 1
    Check the original linked answer as the URL for google fonts changed to `https://github.com/google/fonts/archive/main.tar.gz` and the folder to `$PWD/fonts-main/` – antipopp May 09 '22 at 12:19