We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Opening & saving pdf created from eml file creates invalid document

Steps to reproduce:

  1. Convert .eml file with MailMessage to .mht file
  2. Convert .mht file with Word Document into .pdf
  3. Open & save created pdf with Pdf Document
    Result -> invalid pdf

See attached sample project: emlconvertissue.zip (8.9 KB)


Thanks for contacting support.

I have tested the scenario and have observed that the reasons corrupted final PDF file is being generated because you have instantiated com.aspose.pdf.Document instance without providing argument of previously created PDF file. Therefore resultant file without any page is created. In order to resolve this problem, you need to pass pdfIs object as an argument to com.aspose.pdf.Document(…) constructor. Please take a look over following code snippet and the area where you need to make changes.

For your reference, I have also attached the output generated with latest release of Aspose.Pdf for Java 17.8. original_msg_after_pdf_read_and_save.pdf (61.0 KB)


Path tempFile2 = Paths.get(documentsPath, "original_msg_after_pdf_read_and_save.pdf");
try (InputStream pdfIs = Files.newInputStream(tempFile1);
		OutputStream os = Files.newOutputStream(tempFile2);) {
	com.aspose.pdf.Document pdfDoc = new com.aspose.pdf.Document(pdfIs);
	pdfDoc.save(os, com.aspose.pdf.SaveFormat.Pdf);

oh thanks, i totally overlooked that :man_facepalming:


Thanks for the acknowledgement.

We hope that your problem is resolved with earlier shared code snippet. Please continue using our APIs and in the event of any further query, please feel free to contact.