GemBox Support Forum

Error converting eml with xlsx attachments to pdf

Has anyone seen this error when converting an EML file to PDF:

ReadIndexedMemoryBitmap: unsupported format #3

HRESULT -2147467263

at External.Pdf.Advanced.PdfImage.ReadIndexedMemoryBitmap( bitmap, Int32 bits)
at External.Pdf.Advanced.PdfImage.InitializeNonJpeg( bitmap)
at External.Pdf.Advanced.PdfImage…ctor( document, bitmap)
at External.Pdf.Advanced.PdfImageTable.GetImage( bitmap)
at External.Pdf.Advanced.ContentStreamExtensions.GetImageName(IContentStream this, bitmap)
at .( )
at . ( , )
at .​ ( , , )
at ​ .( , , )
at ​ .( , , )
at ​ .( )
at ​ . ( )
at ​ .( )
at ​ .( )
at ​ .​ ()
at .( , , ​ [] )
at .( , ​ , Int32 )
at . (Int32 , Object , Object )
at GemBox.Document.DocumentModelPaginator.dca75czcds9lmgv2y95q5srjljs9plta (Int32 , Object , Object )
at . ( , String , Stream )
at .( , , Stream )
at GemBox.Document.PdfSaveOptions.67tg5rkvl9zwp8v7723mndgzuc3b4vj8 ( , Stream , Boolean )
at GemBox.Document.PdfSaveOptions.67tg5rkvl9zwp8v7723mndgzuc3b4vj8 (DocumentModel , Stream , String )
at GemBox.Document.DocumentModel.Save(String path, SaveOptions options)
at GemBox.Document.DocumentModel.Save(String path)
at TestGembox.Program.Main(String[] args) in C:\Users\thayes\source\repos\TestGembox\TestGembox\Program.cs:line 47

I have narrowed it down to an EML with an XLSX attachment that contains a logo image. We only see this when running in a Docker container running Linux, it runs fine when we run in Windows. I can replicate this with a client’s email however I have been unable to replicate it with an anonymized version of the email.


FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
RUN sed -i’.bak’ ‘s/$/ contrib/’ /etc/apt/sources.list
RUN apt-get update; apt-get install -y libgdiplus ttf-mscorefonts-installer fontconfig fonts-liberation

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
COPY [“TestGembox.csproj”, “”]
COPY [“ReadIndexedMemoryBitmapError.eml”, “”]
RUN dotnet restore “./TestGembox.csproj”
COPY . .
WORKDIR “/src/.”
RUN dotnet build “TestGembox.csproj” -c Release -o /app/build

FROM build AS publish
RUN dotnet publish “TestGembox.csproj” -c Release -o /app/publish

FROM base AS final

Update package sources to include supplemental packages (contrib archive area).

RUN sed -i ‘s/main/main contrib/g’ /etc/apt/sources.list

Downloads the package lists from the repositories.

RUN apt-get update

Install System.Drawing.Common dependency.

RUN apt-get install -y libgdiplus

Install Microsoft TrueType core fonts.

RUN apt-get install -y ttf-mscorefonts-installer

RUN apt-get install -y fontconfig
RUN apt-get install -y fonts-liberation

Or install Liberation TrueType fonts.

RUN apt-get install -y fonts-liberation

Or some other font package…

COPY --from=publish /app/publish .
RUN pwd
ENTRYPOINT [“dotnet”, “TestGembox.dll”]

Tim H

Hi Tim,

Is that logo image in EMF or WMF format?

GemBox.Document doesn’t directly export EMF or WMF vector image formats into PDF.
Instead, they are first converted to PNG and then exported, see the PdfSaveOptions.MetafileScaleFactor.

However, this conversion doesn’t work on Linux, but it should also not throw an exception so it’s possible that the problem is something else.

Can you please save the HTML content that you get from the ReplaceEmbeddedImages(message.BodyHtml, message.Attachments) into a HTML file.
Then remove the confidential data from that HTML file and check that the following still reproduces your issue:

string html = File.ReadAllText("body.html");
document.Content.End.LoadText(html, LoadOptions.HtmlDefault);

If it does then please send us that HTML file so that we can investigate this.


The original problem doesn’t occur on the latest version of GemBox.Document.

The latest version can be downloaded from our BugFixes page or from NuGet.