Hello,
Using GroupDocs.Conversion.NETFramework v25.11.0, when you convert an email from outlook, format .msg, into a PDF, and the email contains attachments of PDF format, the annotations/stamps are lost at conversion. How can I ensure to keep those ?
Thanks
Annotations within PDFs, not the .msg itself. It can be an annotation for example a drawing that is a signature in the end.
Here is the code :
using (var converter = new Converter(SourceFilePath))
{
var loadOptions = new EmailLoadOptions
{
ConvertOwned = true,
ConvertOwner = true,
PreserveOriginalDate = true,
ResourceLoadingTimeout = TimeSpan.FromSeconds(15),
Depth = 2
};
PdfConvertOptions options = new PdfConvertOptions {
SizeSettings = new PageSizeOptions
{
PageSize = PageSize.A4
},
MarginSettings = new PageMarginOptions
{
Top = 15,
Bottom = 15,
Left = 15,
Right = 15
}
};
converter.Convert((SaveContext context) => File.Create(TempFilePath + @"\" + index++.ToString() + "_" + DestFile),options);
}
Hello @CyrusDaVirus ,
Thank you for contacting us and for your interest in our product.
GroupDocs.Conversion provides a flexible API for controlling the document conversion process. To manage the conversion of attachments in an .msg email, you need to use a LoadOptionsProvider.
Below, I have provided a small example based on your code. Please try using it and share the results with us.
LoadOptions LoadOptionsProvider(LoadContext loadContext)
{
if (loadContext.SourceFormat == EmailFileType.Msg)
{
return new EmailLoadOptions
{
ConvertOwned = true,
ConvertOwner = true,
PreserveOriginalDate = true,
ResourceLoadingTimeout = TimeSpan.FromSeconds(15),
Depth = 2
};
}
if (loadContext.SourceFormat == PdfFileType.Pdf)
{
return new PdfLoadOptions()
{
HidePdfAnnotations = false
};
}
return null;
}
using (var converter = new Converter(SourceFilePath, LoadOptionsProvider))
{
PdfConvertOptions options = new PdfConvertOptions {
SizeSettings = new PageSizeOptions
{
PageSize = PageSize.A4
},
MarginSettings = new PageMarginOptions
{
Top = 15,
Bottom = 15,
Left = 15,
Right = 15
}
};
converter.Convert((SaveContext context) => File.Create(TempFilePath + @"\" + index++.ToString() + "_" + DestFile),options);
}
Hello @evgen.efimov
Thank you for your quick reply. Unfortunately your solution does not fix the issue.
Would there be a simple way to skip the conversion if the file is anyway a PDF ?
I have just checked again the pdf and the field in question is a comment field containing a stamp, added by a mobile device.
@CyrusDaVirus ,
Sorry to hear that this did not work.
In this case, could you please share your .msg file so that I can perform further investigation?
Regarding your question about skipping the conversion, I am not sure whether this is currently possible. I will consult with our developers and get back to you with an update.
Hello @evgen.efimov
Unfortunately I cannot share the file as it contains sensitive information. But I have tried reproducing something similar, with the following steps:
- Open word, open drawing, and with your mouse, draw something
- Save the word in PDF as MyDrawing.pdf
- Take an existing PDF file, open it with Adobe Acrobat Reader
- Create a custom stamp using your MyDrawing.pdf
- Apply the custom stamp and save the pdf
- Place the pdf into a mail in outlook, so that you obtain a .msg file and save it to a folder on your drive
- Convert this msg, you will obtain the mail body, and the PDF, which will not show your drawing anymore but a standard red stamp DRAFT.
Now the result is not exactly the same as with the other PDF, where the stamp is simply dropped, I guess it was created using something else (Producer (iOS Version 18.6.2 (Build 22G100) Quartz PDFContext) than Adobe Acrobat, but still, the result is not as expected.
But I guess, the easiest would be to skip the conversion of a PDF attachment (and copy it as-is) in case the requested conversion is PDF.
Hello @CyrusDaVirus ,
Thank you for providing a detailed description of how we can reproduce this behavior.
I have created a corresponding ticket in our tracking system with ID CONVERSIONNET-8152 and shared it with our development team.
As soon as I receive feedback from them, I will inform you right away.
@CyrusDaVirus ,
Regarding the possibility of skipping the conversion of an attached .pdf file in an .msg email file — yes, this is possible. I have attached a code example below.
var source = "sample-with-attachment.msg";
var loadOptions = new EmailLoadOptions {
ConvertOwner = true,
ConvertOwned = true,
// convert email itself and the attachments
Depth = 2
};
ConvertOptions ConvertOptionsProvider(ConvertContext convertContext)
{
if (convertContext.SourceFormat == PdfFileType.Pdf)
{
return new NoConvertOptions();
}
return new PdfConvertOptions();
}
using (var converter = new Converter(source, (LoadContext loadContext) => loadOptions))
{
var index = 1;
// Note: index = 1 is the email itself, all following indexes are attachments
converter.Convert((SaveContext saveContext) => new FileStream($"converted-{index++}.{saveContext.TargetFormat.Extension}", FileMode.Create) , ConvertOptionsProvider);
}
Please try using it and let us know your feedback.
Hello @evgen.efimov
This is perfect ! Works as expected, provides the PDF untouched.
Thank you very much for your help, much appreciated !
@CyrusDaVirus ,
Glad to hear that this helped.
Please feel free to reach out to us if you have any further questions.