Problem when converting

Hello Support,

We are encountering a small issue when converting an EML file to PDF using the Aspose PDF converter. Some lines are being ignored during the conversion and do not appear in the PDF file.

After analyzing, I found that the issue is caused by lines in the EML file containing a <span> with a <style> tag that is not properly passing through the conversion process. I will provide an example below.

The following line is ignored during conversion:

<p style="margin-top: 0pt; margin-bottom: 0pt; font-size: 12pt;"><span style="font-family: 'Times New Roman'; -aw-import: ignore;">Le jugement n'a pas Ă  ĂȘtre signifiĂ© puisque Madame Ă©tait prĂ©sente lors de l'audience.</span></p>

When modified as shown below, it successfully passes the conversion:

<p style="margin-top: 0pt; margin-bottom: 0pt; font-size: 12pt;"><span style="font-family: Constantia; font-weight: bold; text-decoration: underline;">Le jugement n'a pas Ă  ĂȘtre signifiĂ© puisque Madame Ă©tait prĂ©sente lors de l'audience.</span></p>

Regards

@djalilgpj
Could you please provide version of Aspose PDF you are using and example of file and code so we can recreate this issue?

Hello, those are our technical information

1 - version Aspose

<lib.pdf.aspose.version>23.9</lib.pdf.aspose.version>

2 - code

 @Profile
    public void convertToPdf(final String contentFileName, final MailMessage mailMessage,
                             final String baseDirectory)
            throws PDFConversionException {
        FileOutputStream fos = null;

        try {
            LOGGER.info("Conversion du contenu sous forme d'un fichier PDF");
            LOGGER.info("Message: " + mailMessage.getSubject());

            //Save the Message to output stream in MHTML format
            final ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
            final com.aspose.email.MhtSaveOptions saveOptions =
                    new com.aspose.email.MhtSaveOptions();
            saveOptions.setMhtFormatOptions(com.aspose.email.MhtFormatOptions.HideExtraPrintHeader);
            mailMessage.save(emlStream, saveOptions);

            // Création du Document
            final com.aspose.words.Document doc = new com.aspose.words.Document();
            final com.aspose.words.DocumentBuilder builder =
                    new com.aspose.words.DocumentBuilder(doc);

            // CrĂ©ation de l'entĂȘte
            final SimpleDateFormat sdf = new SimpleDateFormat(MAIL_DATE_FORMAT);
            final BundleServiceImpl bundle = BundleServiceImpl.getInstance();

            builder.writeln(bundle.getString("mail.pdf.date").concat(" ")
                    .concat(sdf.format(mailMessage.getLocalDate())));
            builder.writeln(bundle.getString("mail.pdf.from").concat(" ")
                    .concat(mailMessage.getFrom().toString()));
            builder.writeln(bundle.getString("mail.pdf.to").concat(" ")
                    .concat(mailMessage.getTo().toString()));
            final String cc = mailMessage.getCC().toString();
            if (StringUtils.isNotBlank(cc)) {
                builder.writeln(bundle.getString("mail.pdf.cc").concat(" ").concat(cc));
            }
            builder.writeln(bundle.getString("mail.pdf.subject").concat(" ")
                    .concat(MimeUtility.decodeText(mailMessage.getSubject())));
            builder.writeln();

            // Transformation du mail en Document
            com.aspose.words.LoadOptions lo = new com.aspose.words.LoadOptions();
            lo.setLoadFormat(com.aspose.words.LoadFormat.MHTML);
            com.aspose.words.Document emlDoc =
                    new com.aspose.words.Document(new ByteArrayInputStream(emlStream.toByteArray()),
                            lo);

            // Concaténation des parties du document
            emlDoc.getFirstSection().getPageSetup()
                    .setSectionStart(com.aspose.words.SectionStart.CONTINUOUS);
            doc.appendDocument(emlDoc, com.aspose.words.ImportFormatMode.KEEP_SOURCE_FORMATTING);

            // Enregistrement du Document en pdf
            final File saveFile = new File(baseDirectory, contentFileName);
            fos = new FileOutputStream(saveFile);
            doc.save(fos, com.aspose.words.SaveFormat.PDF);
            LOGGER.info("Document enregistré : " + saveFile.getCanonicalPath());
<a class="attachment" href="/uploads/default/100035">mail_de_avocat@xxxxxxxxxxxx.fr_2024-10-11-17h36_b7b6cd32-770b-447d-b5b5-431c2dbe02f3.pdf</a> (90,4 Ko)



        } catch (Exception e) {
            String message =
                    "Erreur lors de la conversion d'un mail (" + mailMessage.getMessageId() + ") en PDF";
            LOGGER.error(message);
            throw new PDFConversionException(message, e);
        } finally {
            IOUtils.closeQuietly(fos);
        }
    }

example of EML File KO to.zip (111,2 Ko)

@djalilgpj
Do I understand correctly that you are using Aspose Words to convert to PDF, not Aspose PDF library?

Its the code that we have , yes

@djalilgpj
In that case I’ll reassign your question to Aspose Words forum

@djalilgpj It looks like the problem occurs upon converting EML to intermediate MHTML file. You can reproduce the problem using the following code:

com.aspose.email.MailMessage msg = com.aspose.email.MailMessage.load("C:\\Temp\\in.eml");
msg.save("C:\\Temp\\tmp.mhtml", com.aspose.email.SaveOptions.getDefaultMhtml());
com.aspose.words.Document doc = new com.aspose.words.Document("C:\\Temp\\tmp.mhtml");
doc.save("C:\\Temp\\out.pdf");

So I will move the topic into Aspose.Email forum. My colleagues will help you shortly.

1 Like

@djalilgpj
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): EMAILNET-41439

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@djalilgpj
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-27493

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.