.docx or .PDF documentGeneration do not work if a file has Image file or content or PlaceHolder post Deployment on Linux

Hi Support Team,

There is a page where I am adding an Image file in the document for PlaceHolder.
I am not able to add this image file into my generated documents.

There are some of the above mentioned steps that I did on load balancer machine. But still i am getting the same error. EnableUnixSupport,sudo amazon-linux-extras install epel,sudo yum install libgdiplus

I am trying to generate the PDF (.pdf) and Word (docx). on Linux Machine. We have Deployed .net Core project on Linux machine. While generating the documents either PDF or .docx I am getting an error “Error occurred while generating the document the type Initializer for Gdip threw an exception“. But this works on Windows post Deployment

Is there anything I am missing… to install.

@poonammishra Aspose.Words for .NET Standard and .NET 6 use SkiaSharp to deal with graphics, to make it work on Linux you have to add reference either to SkiaSharp.NativeAssets.Linux or to SkiaSharp.NativeAssets.Linux.NoDependencies

If you add reference to SkiaSharp.NativeAssets.Linux, you should also install libfontconfig1 in your system. SkiaSharp.NativeAssets.Linux depends on this library. You can use the following command to install it:

apt-get update && apt-get install -y libfontconfig1

If you do not have rights to install packages, or other reasons not to install libfontconfig1, you can simply use SkiaSharp.NativeAssets.Linux.NoDependencies, which does not require installation of libfontconfig1.

Hi Support Team,

Thanks for your support.

I have followed the steps as mentioned above. But when I try to generate the document .docx and .pdf file with Image file into it with PlaceHolder, Images are not present in these generated documents. I am using Aspose.Imaging [22.9.0]. I am using contentPlaceHolder and Aspose.Imaging libraries into the .docx file and when converting this file into PDF. I replace this contentPlaceHolder with Image file. This works fine on Windows but images do not get displayed on the generated documents on Linux Machine.

@poonammishra What Linux distribution do you use? Also, please provide your source and output documents along with simple code that will allow us to reproduce the problem. We will check the issue and provide you more information.
For testing purposes you can generate the correct document in Windows and then convert the document to PDF in Linux. Is the problem reproducible in such scenario?

Hi,

I am using Amazon Linux version 2.Deployed .net core 3.1 version on Linux. All docs are generated fine except file with image file.png/jpg/gif. Linux is completely separate version.
deployed for some of the client.

@poonammishra Could you please attach your source and output documents along with simple code that will allow us to reproduce the problem?

PDFoutputFile.jpg (20.4 KB)
MacInput File.docx (48.7 KB)
Attached is the .docx input file with ContentPlaceHolder and this is replaced with image into pdfoutput file.
code snippet used

public MemoryStream DoChangesForConversionToPdf(XmlDocument inputXml, MemoryStream memDocx)
{
    using (WordprocessingDocument wDoc = WordprocessingDocument.Open(memDocx, true))
    {
        foreach (var cc in wDoc.ContentControls().ToList())
        {
            var xpath = cc.XPath();
            if (xpath == "") continue;
            if (cc.Tag() == "Image") //Replace Image placeholders with actual images provided in input Xml
                cc.ReplaceImagePlaceholder(wDoc, inputXml);
        }
    }
    memDocx.Position = 0;
    return memDocx;
}

internal MemoryStream DoChangesForImages(XmlDocument inputXml, MemoryStream memDocx)
{
    using (WordprocessingDocument wDoc = WordprocessingDocument.Open(memDocx, true))
    {
        foreach (var cc in from cc in wDoc.ContentControls()
                                            .Where(cc => cc.Tag() == "Image").ToList()
                           let xpath = cc.XPath()
                           where xpath != ""
                           select cc)
        {
            cc.ReplaceImagePlaceholder(wDoc, inputXml);
        }
    }
    memDocx.Position = 0;
    return memDocx;
}

@poonammishra Thank you for additional information. As I can see you do not use Aspose.Words in your code. Looks like you are using Open XML SDK for manipulating your documents. So it is not quite clear how the problem is related to Aspose.Words.

Yes, we are using Aspose.Word
aspose.word.jpg (54.8 KB)

@poonammishra According to the code Aspose.Words is used for conversion MS Word document to PDF. Is the DOCX generated by your application in Linux has the image? If I understand correctly DOCX document is generated/modified by Open XML SDK.

Yes, Linux has ContentPlaceHolder and we can assign the image file to this control. Yes we use OpenXML SDK.

@poonammishra Please attach DOCX document produced by OpenXML SDK (after insertion image) in Linux environment before processing it using Aspose.Words. I will check conversion on my side and let you know how it goes.

Hi Support Team,

Its the same file without Image into it. Rest all is same.Attached is the file PDFoutputFile.jpg (20.4 KB)

File does not have icon pic at left corner

@poonammishra Could you please attach the actual DOCX document (not screenshot) produced by OpenXML SDK (after insertion image) in Linux environment before processing it using Aspose.Words?
Does the image exist in DOCX document before processing it using Aspose.Words?

Hi Support Team,

After updating package.
I was able to generate the .docx file perfectly as suggested by you after installing fontconfig on amazon Linux machine. But after convertToPDF , PDF file generated do not have either image content placeholder or added Image into it.

Hence PDF file do not render image file. Kindly help me on this.

@poonammishra Could you please attach the actual (correct) DOCX document generated on your side and PDF document, that demonstrates the problem.
Also, please make sure that SkiaSharp.NativeAssets.Linux package is referenced by your application.

Yes, SkiaSharp.NativeAssets.Linux is referenced in the application.ADR_2447_copy.docx (36.7 KB)
pdfgenerated.jpg (69.7 KB). Barcode is pic image present into .docx file but same file is converted to PDF and do not have barcode image into pdf file

@poonammishra Thank you for additional information. Unfortunately, I cannot reproduce the problem on my side. I have tested your scenario in Docker:

FROM amazonlinux:2 AS base

# Install .NET6 SDK
RUN rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
RUN yum install dotnet-sdk-6.0 -y

WORKDIR /src
COPY ["TestNet6.csproj", "."]
RUN dotnet restore "./TestNet6.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "TestNet6.csproj" -c Release -o /app/build
RUN dotnet publish "TestNet6.csproj" -c Release -r linux-x64 --no-self-contained -o /app/publish

ENTRYPOINT ["dotnet", "/app/publish/TestNet6.dll"]

Here is .csproj file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>
  
   <PropertyGroup>
     <InvariantGlobalization>false</InvariantGlobalization>
   </PropertyGroup>

  <ItemGroup>
	  <PackageReference Include="Aspose.Words" Version="23.4.0" />
	  <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.3" />
  </ItemGroup>

</Project>

Here is the test code:

using Aspose.Words;
using System;
using System.Diagnostics;

namespace Aspose.NetCore.TestRunner
{
    class Program
    {
        static void Main(string[] args)
        {
            License lic = new License();
            lic.SetLicense("/temp/Aspose.Words.NET.lic");

            Console.WriteLine("Test started.");

            Document doc = new Document("/temp/in.docx");
            doc.Save(@"/temp/out.pdf");

            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds / 1000d);

            Console.WriteLine("Done");
        }
    }
}

I run the test using the following commands:

docker build -f Dockerfile_amazon -t awtest .

docker run --mount type=bind,source=C:\Temp,target=/temp --rm awtest from Docker

The output PDF document looks correct: out.pdf (22.4 KB)

Hi Support Team,

I was able to generate the .PDF document, after following all the steps mentioned above after installation of Skiashap. There is a slight difference between the docs genereted on Linux machine. Bullet point is not correct on Linux machine generated are pdfonLinux.jpg (55.7 KB)
pdfonwindows.jpg (32.7 KB)

Kindly help me on this since this issue is critical and there are major timelines.

@poonammishra This looks like a known peculiarity - Windows “Symbol” font (which is used for bullets) is a symbolic font (like “Webdings”, “Wingdings”, etc.) which uses Unicode PUA. MacOS or Linux “Symbol” font on the other hand is a proper Unicode font (for example Greek characters are in the U+0370…U+03FF Greek and Coptic block). So these fonts are incompatible and Mac/Linux “Symbol” font cannot be used instead of Windows “Symbol” without additional actions. In your particular case, it looks like, the bullet is represented as U+2022, but in Windows “Symbol” it is PUA U+F0B7 (or U+00B7 which also can be used in MS Word for symbolic fonts). So you should change U+2022 character to U+00B7:

Document doc = new Document(@"C:\Temp\in.docx");

List<Run> items = doc.GetChildNodes(NodeType.Run, true).Cast<Run>()
    .Where(r => r.Font.Name == "Symbol").ToList();

foreach (Run r in items)
{
    if (r.Text == "\x2022")
        r.Text = "\x00b7";
}

doc.Save(@"C:\Temp\out.pdf");

Alternatively, you can use “Symbol” from Windows in your Linux environment.