<p>I am using using the Aspose.Email to get attachments out of an Outlook email like this:</p>
var mailMessage = Aspose.Email.Mail.MailMessage.Load(stream);
var attachments = Aspose.Email.Outlook.MapiMessage.FromMailMessage(mailMessage).Attachments;
var pdfAttachment = attachments.ToList()[attachmentIndexDesired];
Then, I am loading the attachment into DataLogics like this:
var pdfStream = new MemoryStream(pdfAttachment.BinaryData);
var pdfDocument = new Datalogics.PDFL.Document(pdfStream);
Here I get the following exception:
PDF Library Error: File does not begin with '%PDF-'. Error number: 537001985
I cannot find anything on this error anywhere.
Note that the initial stream object above is a *.msg Outlook file and originates from a sharepoint SPFile. Also note that if the stream object SPFile is itself a PDF file (as opposed to an attachment to a *.msg file) I can load it into DataLogics just fine.
I know the error is being thrown by the DataLogics library, but is there something about how I am getting the attachment that could be changed/improved that would prevent this error from occurring?
I have tried the scenario by creating a sample MSG file having a PDF attachment. Number of experiments are performed to read this attachment and then comparing it with the original PDF file. However I am afraid that no difference is observed between the attachment binary data and original PDF data read into memory stream. As no modification/change occurs in PDF binary data by using Aspose.Email, therefore it does not seem to be an issue with the Aspose.Email.
Following is the sample code used for testing:
staticprivatevoid Email_607735() { int attachmentIndexDesired = 0; var mailMessage = Aspose.Email.Mail.MailMessage.Load(@“Mail with PDF attachment.msg”); var attachments = Aspose.Email.Outlook.MapiMessage.FromMailMessage(mailMessage).Attachments; var pdfAttachment = attachments.ToList()[attachmentIndexDesired]; var pdfStream = new MemoryStream(pdfAttachment.BinaryData);
using (MemoryStream ms = new MemoryStream()) using (FileStream file = new FileStream(@“OriginalPdf.pdf”, FileMode.Open, FileAccess.Read)) { byte[] bytes = newbyte[file.Length]; file.Read(bytes, 0, (int)file.Length); ms.Write(bytes, 0, (int)file.Length); if(CompareMemoryStreams(pdfStream,ms)) { Console.WriteLine(“Both the streams are equal”); } else { Console.WriteLine(“Both the streams are NOT equal”); } } } privatestaticbool CompareMemoryStreams(MemoryStream ms1, MemoryStream ms2) { if (ms1.Length != ms2.Length) returnfalse; ms1.Position = 0; ms2.Position = 0;
var msArray1 = ms1.ToArray(); var msArray2 = ms2.ToArray();
By chance, just a few minutes ago I was trying to grab the BinaryData from the attachment and convert it to a string that I could read so I could visually inspect its contents. So I did this.
(new StreamReader(new MemoryStream(curAttachment.BinaryData))).ReadToEnd()
When I did that, it printed this error:
“Evaluation copy of Aspose.Email limits to extract only 3 attachments in the messages. Please contact sales@aspose.com to purchase a valid license.”
Kind of strange as I am using my production license, but either way I went ahead and deleted some attachments from the parent *.msg file (it previously had 4) and tried to load it again. Then… poof… it started working.
Seems like it should throw an exception or something instead as that would have made this issue a lot easier to track down.
We are sorry for the inconvenience you have faced. The evaluations limitations are as mentioned in Aspose.Email Evaluation article. It is assumed that users have gone through the introduction section of the documentation before trying the API. However, we’ll see if there is a more suitable way to bring this to user attention.
Another thing: If you are using multiple Aspose APIs in your application, you need to initialize the license for each API individually. If you still face any issue, please feel free to contact us for further assistance in this regard.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.