Docker not taking new installed font for pdf which is present in word document.

Hi,

We are using Gembox to generate PDF file from word document. Our service is hosted on Docker environment and the PDF generated through service has different font than word document. I had already installed required font on docker but still It’s not taking newly installed font for pdf.PDF has generated with some different font. Can you please advise which fonts need to be include in the docker image to resolve the issue?

Hi Sufiya,

Please send us a small Visual Studio project that reproduces this issue so that we can investigate it.

Regards,
Mario

Can I share you my Docker file content, docx file and PDF file.

Hi,

Yes, I’ll try to reproduce your issue using just those files.

Regards,
Mario

Please refer below source code for Docker File! -

# Copy the custom font files from your local machine to the container
COPY "SourceCodeFilePath" /usr/share/fonts/truetype/

# Install fontconfig to manage the fonts
RUN apt-get update && apt-get install -y fontconfig

# Refresh the font cache
RUN fc-cache -f -v

Also at the side of source code -

GemBox.Document.FontSettings.FontsBaseDirectory = "../app/";
document.DefaultCharacterFormat.FontName = "DTL-Argo-T-Light";

I am not able to share docx here.

It seems like you’re copying the font files to “/usr/share/fonts/truetype/” but you’re setting GemBox.Document to look for them in “…/app/”.

Instead, try copying the font files to some other folder and then make sure that the GemBox.Document.FontSettings.FontsBaseDirectory is set to exactly that folder.

I hope this helps.
If the problem remains, please send us a small Visual Studio project that includes both your font files and your DOCX file.
You can send us the project via email or a support ticket, see the Contact page.

Regards,
Mario

I tried to copy my custom font into app directory also.

Let’s see below code in docker file for copying font into app directory.

COPY DockerPDFdemo/fonts/* /app/

But still It’s not working.

Hi Sufiya,

First, I’m not sure if you received our reply on your support ticket, can you please check your mailbox?

Anyway, are you sure that the following command works as expected?

COPY DockerPDFdemo/fonts/* /app/

Without your project, I cannot say this for sure, but I believe this is not working for you as you expect…
So, can you please check what files you end up with in the “/app/” on Docker container?
For example, you could use something like this:

foreach (string file in Directory.GetFiles("/app/", "*.*", SearchOption.AllDirectories))
    Console.WriteLine(file);

Nevertheless, here is what you can try doing instead, set those font files to be copied to the output directory. In other words, have something like the following in your CSPROJ file:

<ItemGroup>
  <None Update="Fonts\DTL-Argo-T-Bold.ttf">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </None>
  <None Update="Fonts\DTL-Argo-T-Light.ttf">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </None>
  <None Update="Fonts\DTL-Argo-T-Regular.ttf">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </None>
</ItemGroup>

Then set the FontSettings.FontsBaseDirectory to the following:

FontSettings.FontsBaseDirectory = "/app/Fonts/";

Does this solve your issue?

Regards,
Mario