Free Support Forum - groupdocs.com

Converting .MSG file with 4 attachments to PDFs only does first 2

I found and I am using EmailLoadOptions.ConvertOwned to use to Convert Emails Attachments to PDF, however the 3rd and 4th Attachments do not show. (and when I turn on show all errors it complains twice about “Unknown file format” (they are just normal.DOCX files that I can open locally like the first two). When I turn off break on all errors or just step through it completes with 3 pages, one for the email and one each for the first two attachments.

var fileStream = new MemoryStream(file);
            var loadOptions = new EmailLoadOptions { ConvertOwned = true, Format = extension switch { "eml" => EmailFileType.Eml, "msg" => EmailFileType.Msg, _ => null } };

            using (Converter converter = new[] { "eml", "msg" }.Contains(extension) ? new Converter(() => fileStream, () => loadOptions ) : new Converter(() => fileStream))
            {
                var pdfstreams = new List<MemoryStream>();
                var pageStream = new GroupDocs.Conversion.Contracts.SaveDocumentStream(() => { pdfstreams.Add(new MemoryStream()); return pdfstreams.Last(); });

                converter.Convert(pageStream, new PdfConvertOptions { });

                if (pdfstreams.Count() == 1)
                    return pdfstreams.First().ToArray();
                else
                {

                    using (Merger merger = new Merger(new MemoryStream(pdfstreams.First().ToArray()), new PdfLoadOptions()))
                    {
                        for (var i = 1; i < pdfstreams.Count; i++)
                            merger.Join(new MemoryStream(pdfstreams[i].ToArray()));

                        var memoryStream = new MemoryStream();
                        merger.Save(memoryStream);
                        return memoryStream.ToArray();
                    }
                }
            }

@johntgold

Please share following details and we’ll look into this scenario:

  • Problematic file
  • API version (e.g. 20.6, 20.11)
  • Output/resultant file that you are getting

@johntgold

Please avail a temporary license here. As you are evaluating the API in trial mode that’s why there’s such a limitation. You may need to avail a GroupDocs.Total for .NET temporary license because you integrated both GroupDocs.Conversion and GroupDocs.Merger APIs in your project.

Thanks That was it

1 Like

@johntgold

You’re welcome.