MSG converted to PDF with empty page of message

Converting MSG file to PDF gives back empty email message page

1 Like

@Andranik_Beglartan

When converting MSG files to PDF, some users have reported encountering an issue where the resulting PDF is empty, particularly when using custom dimensions for small emails. This problem seems to arise specifically when both a small email and custom page size are specified during the conversion process.

To address this issue, it has been acknowledged by the support team that it can be reproduced, and a ticket has been opened in their internal tracking system to investigate and resolve it. The issue has been assigned an ID (CONVERSIONNET-6901) for tracking purposes.

If you are experiencing this problem, it is recommended to check for updates to the GroupDocs.Conversion library, as fixes for such issues are typically included in new releases. For instance, a recent update has addressed similar issues, so ensuring you are using the latest version may resolve the problem.

Here is a basic example of how to convert an MSG file to PDF using GroupDocs.Conversion for .NET:

using System;
using System.IO;
using GroupDocs.Conversion.Options.Convert;

namespace GroupDocs.Conversion.Examples.CSharp.BasicUsage
{
    internal static class ConvertMsgToPdf
    {
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile = Path.Combine(outputFolder, "msg-converted-to.pdf");

            // Load the source MSG file
            using (var converter = new GroupDocs.Conversion.Converter(Constants.SAMPLE_MSG))
            {
                var options = new PdfConvertOptions();
                // Save converted PDF file
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nConversion to pdf completed successfully. \nCheck output in {0}", outputFolder);
        }
    }
}

Make sure to replace Constants.SAMPLE_MSG with the path to your actual MSG file. This code snippet demonstrates the basic usage of the conversion library to convert an MSG file to PDF format.

For further assistance or if you need priority support, consider reaching out to the paid support services offered by GroupDocs.

Sources:
[1]: Empty result when converting any small MSG to PDF with custom width&height
[2]: Convert MSG to PDF | GroupDocs.Conversion .NET API - Aspose

@Andranik_Beglartan

In addition to the above reply, could you please also share the source/problematic MSG file, sample conversion code and specify the GroupDocs.Conversion API version that you are using?
This will help us further investigate the issue.

message (2).msg



using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.Options.Load;

using System.Globalization;
namespace TestConverter
{
    internal class Program
    {
        private const string SourceMsgFile = "message.msg";
        static async Task Main(string[] args)
        {
            new GroupDocs.Conversion.License().SetLicense($"{Directory.GetCurrentDirectory()}/GroupDocs.Conversion.NET.lic");
            var file = await File.ReadAllBytesAsync(SourceMsgFile);
            await GetConvertedMsgFileContent(file, SourceMsgFile);

        }
        public static async Task GetConvertedMsgFileContent(byte[] fileContent, string fileName)
        {
            using var stream = new MemoryStream();
            try
            {
                var loadOptions = GetEmailLoadingOptions();

                using (var converter = new GroupDocs.Conversion.Converter(
                    () => new MemoryStream(fileContent), () => loadOptions))
                {
                    var options = new PdfConvertOptions()
                    {
                        PdfOptions = new PdfOptions
                        {
                            OptimizationOptions = new PdfOptimizationOptions
                            {
                                FontSubsetStrategy = PdfFontSubsetStrategy.SubsetEmbeddedFontsOnly
                            }
                        },
                        PageSize = PageSize.A4,
                        MarginBottom = 15,
                        MarginLeft = 15,
                        MarginRight = 15,
                        MarginTop = 15
                    };
                    converter.Convert(() => stream, options);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Can not convert to pdf {fileName} {ex.Message}", ex);
                throw;
            }
            await File.WriteAllBytesAsync("converted.pdf", stream.ToArray());
        }

        private static EmailLoadOptions GetEmailLoadingOptions()
        {
            CultureInfo.CurrentCulture = new CultureInfo("nl-NL");
            return new EmailLoadOptions
            {
                ConvertOwner = true,
                ConvertOwned = false,
                Depth = 2,
                DisplayBccEmailAddress = true,
                DisplayCcEmailAddress = true,
                FieldTextMap = new Dictionary<EmailField, string>
                {
                    { EmailField.Subject, "Onderwerp" },
                    { EmailField.From, "Van" },
                    { EmailField.To, "Aan" },
                    { EmailField.Attachments, "Bijlage(n)" },
                    { EmailField.Sent, "Verzonden" },
                },
                TimeZoneOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now)
            };
        }
    }
}

Dockerfile


# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
WORKDIR /app
EXPOSE 80

RUN apt-get update && apt-get install -y ffmpeg libgdiplus && apt install -y tzdata
ENV TZ="Europe/Amsterdam"

RUN sed -i 's/^Components: main$/& contrib/' /etc/apt/sources.list.d/debian.sources
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig
RUN fc-cache -f -v


# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["TestConverter.csproj", "."]
RUN dotnet restore "./TestConverter.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./TestConverter.csproj" -c $BUILD_CONFIGURATION -o /app/build

# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./TestConverter.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

COPY ["GroupDocs.Conversion.NET.lic", ""]
COPY ["message.msg", ""]
ENTRYPOINT ["dotnet", "TestConverter.dll"]
1 Like

@Andranik_Beglartan
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CONVERSIONNET-7273

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
We’ll let you know if any additional details are required.

Will the changes been apply to the version that I provided?

@Andranik_Beglartan

Could you please provide more details on the changes you’re referring to? This will help us better understand and assist you.

One more information for you. I have added this package to project and after removing custom size options it converted correctly, but with custom options i am getting black page.

1 Like

@Andranik_Beglartan

Thanks for the additional information. We’ll continue our investigation and notify you in case of any update.

@Andranik_Beglartan

Please take a look at this application (source and output files are included). We couldn’t reproduce this issue at our end when running this application both natively and in Docker.

The issues you have found earlier (filed as CONVERSIONNET-7273) have been fixed in this update. This message was posted using Bugs notification tool by nikola.yankov