Italic functions do not run on the server

I have a project using the gembox document.

  1. The process to generate json into a document .docx

  2. The results of the first process are converted to pdf

On my computer locally everything is running normally. But why when the project is upgraded to the SIT env using docker. The italic/bolditalic function is not readable in the pdf generate results, while the word generate results are successful there is no problem.

FYI, I used the font “Helvetica Neue”.

Can anyone help me fix this?

Hi Ryn,

What font files have you included inside the Docker project?
Note that for creating PDF files you need to have font files, for creating DOCX files you don’t need them.

Can you please send us a small Visual Studio project that reproduces your issue so that we can investigate it?

Regards,
Mario

in function generate pdf, i using font Helvetica Neue.
Below I attach this function to my controller.

public JObject GeneratePDF([FromBody] JObject json)
{
    JObject jsonOut = new JObject();
    int statusCode = 200;

    try
    {
        string filename = json.GetValue("filename").ToString();
        ComponentInfo.SetLicense(lc.decrypt(dbconn.SettingConvert("license_gembox_doc")));

        string PathSave = dbconn.SettingConvert("pathSave");
        if (json.ContainsKey("path_save") && json.GetValue("path_save").ToString() != "")
        {
            PathSave = json.GetValue("path_save").ToString();
        }
        string startupPath = Directory.GetCurrentDirectory();
        string save = startupPath + PathSave + filename;

        DocumentModel document = DocumentModel.Load(startupPath + PathSave + filename + ".docx");
        FontSettings.FontsBaseDirectory = startupPath + PathSave + "HelveticaNeue.ttf";

        foreach (Section section in document.Sections)
        {
            section.PageSetup.PaperType = PaperType.Letter;
            section.PageSetup.Orientation = Orientation.Landscape;
            section.PageSetup.PageMargins.Left = 40;
            section.PageSetup.PageMargins.Right = 40;
            section.PageSetup.PageMargins.Top = 40;
            section.PageSetup.PageMargins.Bottom = 40;
        }

        foreach (Paragraph paragraph in document.GetChildElements(true, ElementType.Paragraph))
        {
            paragraph.ParagraphFormat.SpaceAfter = 1.15;

            foreach (Run run in paragraph.GetChildElements(true, ElementType.Run))
            {
                string text = run.Text;

                if (text.Contains("bold"))
                {
                    run.CharacterFormat.Bold = true;
                }

                if (text.Contains("italic"))
                {
                    run.CharacterFormat.Italic = true;
                }

                if (text.Contains("bolditalic"))
                {
                    run.CharacterFormat.Bold = true;
                    run.CharacterFormat.Italic = true;
                }

                run.CharacterFormat.FontName = "Helvetica Neue";
                run.CharacterFormat.Size = 11;
            }
        }

        document.Save(save + ".pdf");
        jsonOut.Add("status", "Success");
        jsonOut.Add("message", mc.GetMessage("api_output_ok"));
        jsonOut.Add("data", filename + ".pdf");
    }
    catch (Exception ex)
    {
        statusCode = 500;
        jsonOut = new JObject();
        jsonOut.Add("status", mc.GetMessage("api_output_not_ok"));
        jsonOut.Add("message", ex.Message);
        jsonOut.Add("isSuccess", false);
        jsonOut.Add("code", statusCode);
    }
    return jsonOut;
}

on my local computer it worked, but for some reason when I pushed it to the SIT environment it didn’t work

I suspect whether there is a special configuration that must be applied to Docker?

Hi Ryn,

Yes, you need to install the fonts that you’re using.
For example, if your document has regular, bold, and italic Calibri text, then you would need to have the following font files on the Docker:

  • calibri.ttf
  • calibrii.ttf
  • calibrib.ttf

So again, can you please share with us a small Visual Studio project that shows what settings you currently have for the Docker?

Regards,
Mario

# Base image dotnet sdk using debian 10 slim
#FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build-env
FROM /production/sdk:5.0-ironpdf AS build-env

# Working directory project
WORKDIR /apps

# Remove folder apps
RUN rm -rf /apps \
  && mkdir -p /apps

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . . ./
RUN dotnet publish -c Release -o publish

# Multistage build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim

# Default labels
LABEL copyright="example"
LABEL website="example.com"

# Container Working directory and copy build runtimes
WORKDIR /apps
COPY --from=build-env /apps/publish .

# Install tzdata and set timezome Asia Jakarta
RUN apt-get update && apt-get install --no-install-recommends -y tzdata \
  && ln -fs /usr/share/zoneinfo/Asia/Jakarta /etc/localtime \
  && dpkg-reconfigure -f noninteractive tzdata \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*

# Install dependencies ironodf
RUN apt-get update && apt-get install --no-install-recommends -y curl \
  libx11-xcb1 \
  libappindicator3-1 \
  libatk-bridge2.0-0 \
  libnss3 \
  libc6-dev \
  libgbm1 \
  libfontconfig1 \
  libdrm-common \
  libxcb-dri3-0 \
  libxrender1 \
  libgtk2.0-0 \
  libc6 \
  libxshmfence1 \
  libasound2 \
  libgdiplus \
  musl \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/* 

# create a new user and change directory ownership
RUN adduser --disabled-password \
  --home /apps \
  --gecos '' example && chown -R example/apps

# impersonate into the new user
USER example
WORKDIR /apps

# Default settings environment projects
ENV ASPNETCORE_URLS=http://*:8000
ENV ASPNETCORE_ENVIRONMENT="production"

# Expose port
EXPOSE 8000

# Remove unused folder windows, because ironpdf using linux distribution 
RUN rm -f /apps/myconfig.json \
  && ln -s /apps/config/myconfig.json /apps/myconfig.json \
  && ln -s /apps/config/myfolder/myproject/files /apps/
  
# Entrypoint for running dotnet
ENTRYPOINT ["dotnet", "myproject.dll"]

This is the docker file in the gitlab repository

If you really need to configure something in the docker file, please tell me the example code to install the “Helvetica Neue” font, both normal, italic, bold italic

Hi,

Unfortunately, without running your project I was unable to confirm exactly where the issue is.
Nevertheless, I believe the problem is with this:

FontSettings.FontsBaseDirectory = startupPath + PathSave + "HelveticaNeue.ttf";

To what value are you setting the FontSettings.FontsBaseDirectory?
Note that this value should be the path to the directory that has font files.

So, it’s possible that you need startupPath + PathSave, however, for me to confirm that I would need a project from you that reproduces your issue so that I can run it on my end and debug it.

Another issue that is probably happening here is that you only have the “HelveticaNeue.ttf” font file, but what you additionally need to have is “HelveticaNeueBold.ttf”, “HelveticaNeueItalic.ttf”, and “HelveticaNeueBoldItalic.ttf” files.

For example, take a look at the font files that are included on your local machine for the “Calibri” font:

As you can see, it has multiple font files (one for regular glyphs, one for bold glyphs, one for italic glyphs, etc.).

I hope this helps.

If you need more, please create a small Visual Studio project that I can run on my end so that I can further investigate your issue.

Regards,
Mario

This has been solved, you really have to install the related font on the server