Aspose docx to pdf library implementation is functioning correctly with the proper license key in our standard development environment. However, it is not running in our AKS/containerized UAT environment. Kindly assist at the earliest.
Error message: Process terminated. Couldn’t find a valid ICU package installed on the system. Set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support.
@Subhadeep
It seems that you are encountering an issue with the Aspose library in your AKS/containerized UAT environment, specifically related to the ICU package. The error message indicates that the system cannot find a valid ICU package, which is necessary for globalization support.
To resolve this issue, you may need to install the libicu-dev
package in your container. Here’s a sample Dockerfile configuration that you can use as a reference for setting up your environment:
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND="noninteractive"
RUN apt-get update -y
RUN apt-get install -y python3-pip
RUN apt-get install -y libpython3.7
RUN apt-get install -y pkg-config libicu-dev
WORKDIR /usr/app/src
# Copy your application code
COPY app.py ./
RUN pip install aspose-words
CMD [ "python3", "app.py"]
Make sure to adapt the Dockerfile to fit your specific application needs. After adding the libicu-dev
package, rebuild your container and try running your application again. This should help in resolving the error you are facing.
If you continue to experience issues, please check the Aspose documentation for any additional requirements related to running Aspose.Words in a Linux environment.
Sources:
[1]: Error - Couldn’t find a valid ICU package installed on the system
[2]: Utilize the aspose license in python
@Subhadeep Please try installing ICU package. For example for cent os you can install it using the following command:
# Install ICU package.
RUN yum -y install icu
Please see our github to find different docker files:
https://github.com/aspose-words/Aspose.Words-for-Python-via-.NET/blob/master/Dockerfile
We have configured the docker file as below
FROM python:3.9-alpine
RUN apk update && apk add --no-cache pandoc
RUN apk update && apk add --no-cache \
build-base \
gcc \
gfortran \
musl-dev \
linux-headers \
libffi-dev \
openssl-dev \
bzip2-dev \
zlib-dev \
libssl-dev
# Install dependencies
# RUN apt-get update && apt-get install -y \
# gcc \
# libffi-dev \
# libssl-dev \
# && rm -rf /var/lib/apt/lists/*
WORKDIR /var/app
ADD ./requirements.txt /var/app
ADD ./document.docx /var/app
ADD ./Aspose.Words.Python.NET.lic /var/app
RUN pip3 install -r requirements.txt
# RUN mkdir /var/app
ADD . /var/app
RUN mkdir logo
RUN mkdir media
RUN mkdir media/media
ARG PORT=54000
EXPOSE ${PORT}
CMD ["python", "postCall.py"]
Our requirement.txt file is as below
aspose-words==24.11.0
sqlalchemy==2.0.31
python-docx==0.8.11
flask==2.3.2
glob2==0.7
pypandoc==1.11
pandoc==2.3
datetime==4.9
pandas==1.1.5
numpy==1.26
NB - In our application pandoc library is used for separate purpose
Our postcall.py code is mentioned below
# Set the license
def apply_license():
license = aw.License()
try:
# Option 1: If you have a license file
license.set_license("/var/app/Aspose.Words.Python.NET.lic")
# Option 2: If you have the license content as a string
# license.set_license_from_string("your-license-key-string")
print("License set successfully.")
except Exception as e:
print(f"Error applying license: {e}")
@app.route('/docxToPdf', methods=['POST'])
def docxToPdf():
record = json.loads(request.data)
# Decode the base64 string data
decoded_data = base64.b64decode(record['base64string'])
# Generate a unique filename based on the current date and time
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
input_filename = f"./Input_{timestamp}.docx"
output_filename = f"./converted_{timestamp}.pdf"
# Save the received DOCX data to a file
with open(input_filename, "wb") as input_file:
input_file.write(decoded_data)
# Apply the license
print("enter to DocxToPDF, closing apply license....")
apply_license()
# Convert DOCX to PDF using Aspose.Words
doc = aw.Document(input_filename)
doc.save(output_filename)
# Convert the PDF to base64
with open(output_filename, "rb") as output_file:
pdf_data = output_file.read()
base64_str = base64.b64encode(pdf_data).decode('utf-8')
# Clean up the files (delete input and output files)
os.remove(input_filename)
os.remove(output_filename)
return jsonify({'base64string': base64_str})
Please need your assistance as soon as possible.
@Subhadeep Please try also installing ICU lib:
RUN apk add --no-cache icu-libs