We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

HTML not converting correctly in Linux Docker Container - fine on Windows

I am trying to run the Aspose.HTML code in a Linux Docker container but getting different outcomes compared to when I run it on a windows machine.

I am trying to convert this HTML to PDF and PNG.

Example HTML

When I convert it on a windows machine it looks like this :

converted_1.png (7.6 KB)
converted.pdf (44.9 KB)

but when I convert it in a linux docker container it looks like this :

converted.png (3.0 KB)
converted.pdf (33.8 KB)

Here is the code I am using :

var html = System.IO.File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "test.html"));

var document = new HTMLDocument(html, string.Empty);
var options = new PdfSaveOptions
    PageSetup =
        AnyPage = new Aspose.Html.Drawing.Page(new Size(1203,403),
            new Margin(0, 0, 0, 0))

var pngImageOptions = new ImageSaveOptions
    Format = ImageFormat.Png,
    Compression = Compression.None,
    SmoothingMode = SmoothingMode.HighQuality,
    PageSetup =
        AnyPage = new Aspose.Html.Drawing.Page(
            new Aspose.Html.Drawing.Size(1203,403), new Margin(0, 0, 0, 0))

var document = new HTMLDocument(html, string.Empty);

// Convert HTML to PDF
Converter.ConvertHTML(document, options, Path.Combine(Directory.GetCurrentDirectory(), "converted.pdf"));
Converter.ConvertHTML(document, pngImageOptions, Path.Combine(Directory.GetCurrentDirectory(), "converted.png"));

I have installed the standard fonts using the code below within the docker file and I have confirmed they are in the right place. It seems to be loading the fonts fine. Just the text is being stretched.

RUN apt update && apt install -y libc6 libgdiplus libc6-dev libgtk2.0-0 libnss3 libatk-bridge2.0-0 libx11-xcb1 libxcb-dri3-0 libdrm-common libgbm1 libasound2 libappindicator3-1 libxrender1 libfontconfig1 libxshmfence-dev

RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list

RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig

Can anyone explain why this is happening or what I can do to stop it ?



An issue as HTMLNET-4132 has been logged in our issue tracking system for the sake of further investigation of this case. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

1 Like