Unable to convert MSG files to PDF/A-2A format

Test msg file with problematic characters.zip (6.6 KB)
Hi Team,

We are facing an issue while converting MSG file to PDF/A-2A format.
steps: First we will convert MSG file to PDF and this PDF to A-2A format. it converts to normal PDF but from PDF to A-2A format unable.

The MSG file contains some special characters like squares. Only such files are unable to convert and rest of files does well.

we have used below code to do so

public static bool ConvertEmailToPdf(string sourcePath, string destinationPath)
    {
        using (var mailMsg = MailMessage.Load(sourcePath))
        {
            var mhtSaveOptions = new MhtSaveOptions
            {
                MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.WriteCompleteEmailAddress
            };
            using (var msgStream = new MemoryStream())
            {
                mailMsg.Save(msgStream, mhtSaveOptions);

                msgStream.Position = 0;
                var options = new LoadOptions
                {
                    LoadFormat = LoadFormat.Mhtml
                };
                var document = new Document(msgStream, options);
                var sourceDirectory = Path.GetDirectoryName(destinationPath);
                if (sourceDirectory != null)
                {
                    Directory.CreateDirectory(sourceDirectory);
                }
                var saveOptions = new PdfSaveOptions
                {
                    SaveFormat = SaveFormat.Pdf,
                    UpdateLastSavedTimeProperty = true
                };
               document.Save(destinationPath, saveOptions);
            }
            return AsposePdf. ConvertToPdfA2A(destinationPath, destinationPath);
        }
    }



public static bool ConvertToPdfA2A(Document pdfDocument, string destinationFilePath)
    {
        pdfDocument.Convert(new MemoryStream(), PdfFormat.PDF_A_2A, ConvertErrorAction.Delete);

        if (File.Exists(destinationFilePath))
            File.Delete(destinationFilePath);

        var destinationDirectory = Path.GetDirectoryName(destinationFilePath);
        if (!string.IsNullOrWhiteSpace(destinationDirectory))
            Directory.CreateDirectory(destinationDirectory);

        if (!pdfDocument.Info.ContainsKey(Constants.ModDate))
            pdfDocument.Info.ModDate = pdfDocument.Info.CreationDate;

        pdfDocument.Save(destinationFilePath);

        return CheckPdfFormat(destinationFilePath, PdfFormat.PDF_A_2A);
    }

output.pdf (40.8 KB)

Please suggest how can we convert this kind of special characters PDF files to PDFA-2A format.

thanks

@ITCUser

Thank you for contacting support.

We have worked with the data shared by you and have not been able to reproduce the problem. The .msg file is converted to a PDF/A document fine. We have attached generated files along with the code snippet used for this conversion, for your kind reference. Please ensure using Aspose.Email for .NET 18.4 and Aspose.PDF for .NET 18.5 in your environment and then share your kind feedback with us.

        using (var mailMsg = Aspose.Email.MailMessage.Load(dataDir + "Test msg file with problematic characters.msg"))
        {
            var mhtSaveOptions = new Aspose.Email.MhtSaveOptions
            {
                MhtFormatOptions = Aspose.Email.MhtFormatOptions.WriteHeader | Aspose.Email.MhtFormatOptions.WriteCompleteEmailAddress
            };
            using (var msgStream = new MemoryStream())
            {
            mailMsg.Save(msgStream, mhtSaveOptions);
            msgStream.Position = 0;
            MhtLoadOptions options = new MhtLoadOptions();
            var document = new Document(msgStream, options);
            document.Save(dataDir + "MHT2PDF.pdf" , SaveFormat.Pdf);
        }

        // load the source PDF file
        Aspose.Pdf.Document pdfDocument = new Document(dataDir + "MHT2PDF.pdf");

        pdfDocument.Convert(new MemoryStream(), PdfFormat.PDF_A_2A, ConvertErrorAction.None);

        // save the updated document
        pdfDocument.Save(dataDir + "PDF_A2A_18.5.pdf");

MSG2PDFA.zip (353.8 KB)

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Thank you for your response,

we have shared MSG file which have square kind of shapes in msg file, where I saw in your attachment it contains MHT file and it doesn’t contain special characters as attachedspecialchars.PNG (1.2 KB)

@ITCUser,

We opened the sample MSG file shared by you it contains “dots” (special characters). Screenshot is attached for your reference. When this MSG file is converted to MHT format, the converted MHT file contains blank spaces. This issue has been logged into our system with ID EMAILNET-38988 for further investigation. We will update you here once there is some information or a fix version available in this regard.
special_Char_in_Msg.jpg (68.1 KB)