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