Hi
We are using Aspose.Email 4.5.0.0 and Aspose.Pdf 9.3.1 to convert e-mails to PDF/A1B.
When we convert e-mails with embedded images, the image is lost in the PDF file and replaced by a big X.
I’ve attached an example to this post.
Could you investigate?
Kind regards,
Bart Maes
ECM Consultant
Docbyte sa
Hi Bart,
Thanks for your inquiry. We have tested the scenario using the latest version of Aspose.Email, Aspose.Words, and Aspose.Pdf Jars and were unable to notice the reported issue. We would appreciate it if you could share your sample code here, so we can test the scenario and provide you with more information accordingly.
// MSG to MHTML using Aspose.Email
FileInputStream fstream = new FileInputStream(myDir + "Mail met tekening in.msg");
MailMessage eml = MailMessage.load(fstream);
Save the message to output stream in MHTML format
ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
eml.save(emlStream, MailMessageSaveType.getMHtmlFormat());
//MHTML to PDF using Aspose.Words
Load the stream in Word document
com.aspose.words.LoadOptions lo = new com.aspose.words.LoadOptions();
lo.setLoadFormat(com.aspose.words.LoadFormat.MHTML);
com.aspose.words.Document doc = new com.aspose.words.Document(new ByteArrayInputStream(emlStream.toByteArray()), lo);
//Save to disc
doc.save(myDir + "Mail met tekening in.pdf", com.aspose.words.SaveFormat.PDF)
// PDF to PDFA1b conversion using Apsose.Pdf
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(myDir + "Mail met tekening in.pdf");
// Convert to PDF/A compliant document
//pdfDocument.validate("Validation_log.xml",com.aspose.pdf.PdfFormat.PDF_A_1A);
pdfDocument.convert("Conversion_log.xml",com.aspose.pdf.PdfFormat.PDF_A_1B,com.aspose.pdf.ConvertErrorAction.Delete);
// Save updated document
pdfDocument.save(myDir + "pdfa1b_pdf.pdf");
Please feel free to contact us for any further assistance.
Best Regards,
Hi Tilal
Here is part of our code to convert e-mail to PDF.
The contents of the e-mail are retrieved with mail.getHtmlBody();
MailMessageLoadOptions mailOptions = new MailMessageLoadOptions();
mailOptions.setMessageFormat(MessageFormat.getMsg());
mailOptions.setFileCompatibilityMode(FileCompatibilityMode.SkipValidityChecking);
MailMessage mail = MailMessage.load(inFilePath, mailOptions);
Document doc = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);
docBuilder.insertHtml(mail.getHtmlBody());
ByteArrayOutputStream docOut = new ByteArrayOutputStream();
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setCompliance(PdfCompliance.PDF_A_1_B);
doc.save(docOut, saveOptions);
Kind regards,
Bart
Hi Bart,
Hi Bart,
String dir = “579482\”;
MailMessage msg = MailMessage.load(dir + “Mail met tekening in.msg”);
// Save all embedded images
for(LinkedResource lr:msg.getLinkedResources())
{
lr.save(dir + lr.getContentId());
}
//Replace ContentsID with path to images
String strHtmlContents = msg.getHtmlBody().replace(“cid:”, “”);
//Save the HTML contents to file
FileOutputStream fop = null;
File file;
try {
file = new File(dir + “Test.html”);
fop = new FileOutputStream(file);
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
// get the content in bytes
byte[] contentInBytes = strHtmlContents.getBytes();
fop.write(contentInBytes);
fop.flush();
fop.close();
}
catch(Exception e)
{}
Document doc = new Document(dir + “Test.html”);
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setCompliance(PdfCompliance.PDF_A_1_B);
doc.save(dir + “Test.pdf”, saveOptions);