File size: 5,320 Bytes
86fce4f
 
 
 
 
 
 
 
ecbfb06
 
 
 
b6b0869
 
 
 
c677bad
86fce4f
0217eab
86fce4f
 
 
 
 
 
b6b0869
86fce4f
 
 
 
 
 
 
 
 
 
2760df1
 
 
 
86fce4f
 
 
 
 
0217eab
 
 
 
86fce4f
 
2760df1
 
 
 
 
 
86fce4f
 
 
927edae
 
 
ff4fc54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b6b0869
 
 
 
 
 
c677bad
 
 
 
 
 
ff4fc54
 
 
 
 
0217eab
 
e15716d
86fce4f
 
 
ecbfb06
 
 
 
 
7d3b1e2
 
927edae
 
 
 
ecbfb06
14a7592
927edae
30b350e
e15716d
 
dc4dad8
 
e15716d
 
 
 
ecbfb06
b6b0869
dc4dad8
14a7592
 
 
 
 
 
86fce4f
 
927edae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Dockerfile for DOCX to PDF Converter with Enhanced Arabic Support
FROM ubuntu:22.04

# Set environment variables for Arabic support
ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=ar_SA.UTF-8
ENV LC_ALL=ar_SA.UTF-8
ENV PYTHONUNBUFFERED=1
# Set environment variables for LibreOffice
ENV HOME=/tmp
ENV TMPDIR=/tmp
ENV XDG_CONFIG_HOME=/tmp/.config
# CRITICAL: Completely disable Java to prevent javaldx errors
ENV SAL_DISABLE_JAVA=1
ENV SAL_DISABLE_JAVA_SECURITY=1
ENV LIBO_DISABLE_JAVA=1
ENV UNO_PATH=/usr/lib/libreoffice/program

# Install system dependencies including Arabic fonts and Microsoft fonts
RUN apt-get update && apt-get install -y \
    python3 \
    python3-pip \
    libreoffice \
    libreoffice-writer \
    libreoffice-l10n-ar \
    # REMOVED: libreoffice-java-common and openjdk-11-jre-headless to prevent javaldx errors \
    fonts-liberation \
    fonts-liberation2 \
    fonts-dejavu \
    fonts-dejavu-core \
    fonts-dejavu-extra \
    fonts-croscore \
    fonts-noto-core \
    fonts-noto-ui-core \
    fonts-noto-mono \
    fonts-noto-color-emoji \
    # ADDED: Available Arabic fonts in Ubuntu 22.04
    fonts-noto-naskh-arabic \
    fonts-noto-kufi-arabic \
    fonts-hosny-amiri \
    fontconfig \
    wget \
    curl \
    unzip \
    locales \
    # Add Microsoft fonts for Arial support
    fonts-freefont-ttf \
    # Add unoconv for fallback conversion
    unoconv \
    && rm -rf /var/lib/apt/lists/*

# Manually install Scheherazade New font from Google Fonts
RUN mkdir -p /usr/share/fonts/truetype/scheherazade \
    && wget -q https://github.com/google/fonts/raw/main/ofl/scheherazadenew/ScheherazadeNew-Regular.ttf -O /usr/share/fonts/truetype/scheherazade/ScheherazadeNew-Regular.ttf \
    && wget -q https://github.com/google/fonts/raw/main/ofl/scheherazadenew/ScheherazadeNew-Bold.ttf -O /usr/share/fonts/truetype/scheherazade/ScheherazadeNew-Bold.ttf \
    && fc-cache -fv

# Generate Arabic locale
RUN locale-gen ar_SA.UTF-8

# Update font cache
RUN fc-cache -fv

# Fix LibreOffice Java integration issues - Comprehensive fix
# Create all necessary LibreOffice directories with proper permissions
RUN mkdir -p /tmp/.config/libreoffice/4/user \
         /usr/lib/libreoffice/share/fonts/truetype \
         /usr/lib/libreoffice/share/fonts/type1 \
    && chmod -R 777 /tmp/.config \
    && chmod -R 777 /usr/lib/libreoffice/share/fonts || true

# Create empty registrymodifications.xcu to prevent initialization errors
RUN echo '<?xml version="1.0" encoding="UTF-8"?>\

<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\

  <!-- Disable first start wizard and user installation -->\

  <item oor:path="/org.openoffice.Setup/Office/Factories/org.openoffice.Setup:Factory['\''com.sun.star.comp.framework.ProtocolHandler'\'']">\

    <prop oor:name="FirstStartWizardCompleted" oor:op="fuse">\

      <value>true</value>\

    </prop>\

  </item>\

  <!-- CRITICAL: Disable Java completely to prevent javaldx errors -->\

  <item oor:path="/org.openoffice.Setup/Office">\

    <prop oor:name="JavaSupport" oor:op="fuse">\

      <value>false</value>\

    </prop>\

  </item>\

  <!-- Disable Java security to prevent javaldx errors -->\

  <item oor:path="/org.openoffice.Office.Java">\

    <prop oor:name="Enabled" oor:op="fuse">\

      <value>false</value>\

    </prop>\

  </item>\

</oor:items>' > /tmp/.config/libreoffice/4/user/registrymodifications.xcu \

    && chmod 666 /tmp/.config/libreoffice/4/user/registrymodifications.xcu



# Pre-initialize LibreOffice to avoid first-run errors - More comprehensive approach

# Run LibreOffice with specific flags to complete initial setup

# REMOVED --disable-java flag as it's not supported in LibreOffice 7.3.7.2

RUN HOME=/tmp timeout 30 libreoffice --headless --invisible --nologo --norestore --nofirststartwizard --safe-mode --version || true



# Set working directory

WORKDIR /app



# Copy requirements first to leverage Docker cache

COPY requirements.txt .

RUN pip3 install --no-cache-dir -r requirements.txt



# Create necessary directories with proper permissions

RUN mkdir -p /tmp/libreoffice_conversion /tmp/.config /tmp/fonts/truetype \

    && chmod -R 777 /tmp



# Create static directory

RUN mkdir -p static



# Copy all remaining files

COPY . .



# Setup additional Arabic fonts using Python script with proper permissions

# Use /tmp for font installation to avoid permission issues

RUN sed -i 's|/usr/share/fonts/truetype|/tmp/fonts/truetype|g' setup_fonts.py && \

    mkdir -p /tmp/fonts/truetype/arabic-enhanced && \

    chmod -R 777 /tmp/fonts/truetype && \

    python3 setup_fonts.py || echo "Font setup failed, continuing with default fonts..."



# Update font cache after installing additional fonts

RUN fc-cache -fv



# REMOVED: Java paths and symbolic links that were causing javaldx errors



# Expose port (Hugging Face Spaces requires port 7860)

EXPOSE 7860



# Health check (Hugging Face Spaces requires port 7860)

HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \

    CMD curl -f http://localhost:7860/health || exit 1



# Run the application

CMD ["python3", "main.py"]