Unable to set margins when converting .eml to .pdf after upgrading to 24.8 from 22.8.1

I use the code below to convert .eml files to .pdf. However, setting the margins using options.setMarginBottom(12), options.setMarginTop(12), options.setMarginLeft(12), and options.setMarginRight(12) no longer works after moving from version 22.8.1 to 24.8. The margin settings no longer have an effect.

    try {

        Converter converter = new Converter(()->new ByteArrayInputStream(contents), new DefaultLoadOptionsProvider());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfConvertOptions options = createPdfConvertOptions();
        options.setPageSize(PageSize.LETTER);
        //set 1/4 inch margins for printing
        options.setMarginBottom(12);
        options.setMarginTop(12);
        options.setMarginLeft(12);
        options.setMarginRight(12);
        converter.convert(()->baos, options);
        return ConverterFile.builder().filename(filename).contents(baos.toByteArray()).
                documentSourceEnum(DocumentSourceEnum.GROUPDOCS).isEmailBody(true).build();
    } catch (Exception e) {
        log.error("Problems converting email due to: ",e);
        throw e;
    }

import com.groupdocs.conversion.contracts.LoadOptionsProvider;
import com.groupdocs.conversion.options.load.EmailLoadOptions;
import com.groupdocs.conversion.options.load.LoadOptions;

public class DefaultLoadOptionsProvider implements LoadOptionsProvider {
@Override
public LoadOptions get() {
EmailLoadOptions loadOptions = new EmailLoadOptions();
loadOptions.setDepth(0);
return loadOptions;
}
}

@jayleggett

It seems that you are experiencing issues with setting margins when converting .eml files to .pdf after upgrading from version 22.8.1 to 24.8. This could be due to changes in the library’s handling of margin settings in the newer version.

To troubleshoot this issue, you can try the following steps:

  1. Check Documentation: Ensure that the method for setting margins has not changed in the new version. You can refer to the official documentation for any updates regarding the PdfConvertOptions class and its margin settings.

  2. Test with Default Options: Temporarily remove the margin settings and see if the conversion works without them. This can help determine if the issue is specifically related to margin settings.

  3. Review Release Notes: Look at the release notes for version 24.8 to see if there are any breaking changes or updates related to the conversion process that might affect margin settings.

  4. Sample Code: Here’s a simplified version of your code that you can use to test the conversion with margins:

    try {
        Converter converter = new Converter(() -> new ByteArrayInputStream(contents), new DefaultLoadOptionsProvider());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfConvertOptions options = new PdfConvertOptions();
        options.setPageSize(PageSize.LETTER);
        options.setMarginBottom(12);
        options.setMarginTop(12);
        options.setMarginLeft(12);
        options.setMarginRight(12);
        converter.convert(() -> baos, options);
        return ConverterFile.builder().filename(filename).contents(baos.toByteArray())
                .documentSourceEnum(DocumentSourceEnum.GROUPDOCS).isEmailBody(true).build();
    } catch (Exception e) {
        log.error("Problems converting email due to: ", e);
        throw e;
    }
    
  5. Seek Community Help: If the issue persists, consider posting your question on the GroupDocs support forum or checking if others have encountered similar issues after the upgrade.

If you continue to have trouble, please provide any error messages or additional context that might help in diagnosing the problem further.

Sources:
[1]: Load Email document with options | Documentation

I’ve already checked the listed items.

@jayleggett ,

Please disregard the previous response, our bot may sometimes be inaccurate. Thank you for the provided information, we will investigate this issue and get back to you with the results as soon as possible.

Hello @jayleggett ,

Unfortunately, we were unable to reproduce this issue using Conversion 25.1. For us, setting margins when converting .eml to .pdf works correctly. Could you clarify why you are not using version 25.1 for conversion, as well as which operating system (Windows, Linux, MacOS) the conversion is taking place on?

I have to use 24.8 due to the issue you’re fixing in CONVERSIONJAVA-2753

@jayleggett ,

We have also tested this functionality with Conversion 24.8, but we still cannot reproduce the issue. We attempted to set the margins in two cases—12 and 50—and obtained the correct result.
Screenshot_1.jpg (130.7 KB)

Below is an example of the code and the file we used based on your example:

        EmailLoadOptions loadOptions = new EmailLoadOptions();
        loadOptions.setDepth(0);
        Converter converter = new Converter("invitation.eml", ()->loadOptions);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfConvertOptions options = new PdfConvertOptions();
        options.setPageSize(PageSize.LETTER);      
        options.setMarginBottom(50);
        options.setMarginTop(50);
        options.setMarginLeft(50);
        options.setMarginRight(50);        
        converter.convert(()-> baos, options);
        try(OutputStream outputStream = new FileOutputStream("eml_to_pdf_50.pdf")) {
            baos.writeTo(outputStream);
        } catch (Exception e){
            throw new RuntimeException(e.getMessage());
        }

Could you please clarify which operating system you are using for the conversion?

I’m testing on Windows 11.

@jayleggett ,

In this case, could you create a simple demo example that reproduces this issue and that we can run on our side for verification? You can base it on our GitHub demo examples. This will help us to quickly understand this situation and help you.

If you need to protect personal data from the test .eml file again, please let us know, and we will make this topic private.
We look forward to your example.

I will work on an example tomorrow that reproduces the issue. I’m seeing same issue on Windows and Linux.

Hello @jayleggett ,

Alright, we’ll be waiting for it.

I updated one of the GroupDoc samples, and I could only reproduce the issue with version 24.8. After upgrading to version 25.1 the problem goes away. Once CONVERSIONJAVA-275 is resolved, I will upgrade to resolve the margin problem.