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

Free Support Forum - aspose.com

Can't convert msg into pdf properly

Hi

We are using aspose.Total.Java.License and latest aspose jar and converting msg into pdf. My code snippet is below:
public void convertToPDF(String PDFPath, String DocPath) throws Exception {
FileInputStream fstream = new FileInputStream(DocPath);

	License emailLicense = new License();
	try {
		emailLicense.setLicense("../Aspose.Total.Java.lic");
	} catch (Exception e) {
		e.printStackTrace();
	}
	com.aspose.words.License wordLicense = new com.aspose.words.License();
	try {
		wordLicense.setLicense("../Aspose.Total.Java.lic");
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	MailMessage eml = MailMessage.load(fstream);
	// Save the Message to output stream in MHTML format
    ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
    eml.save(emlStream, SaveOptions.getDefaultMhtml());
    
    // Load the stream in Word document
    LoadOptions lo = new LoadOptions();
    lo.setLoadFormat(LoadFormat.MHTML);
    Document doc = new Document(new ByteArrayInputStream(
                    emlStream.toByteArray()), lo);

    
    // Save to disc
    doc.save( PDFPath, com.aspose.words.SaveFormat.PDF);
    fstream.close();

    System.out.println("Done");

}

but we didn’t get the expected pdf.i am attaching the msg file also.Please look into this. it is very important for us.

Thanks in advancePhoto.zip (152.2 KB)

@sheoran531994

We generated the PDF file using the code snippet and the sample file that you provided. Proper PDF file was generated using the latest version of Aspose APIs. We have attached the generated PDF file for your convenience. Please check the attached file and let us know if it is according to your expectation. If not, then please provide additional details about the expected output that you want to generate.

Photo.pdf (180.0 KB)

There are two images in this msg file. First file is as our expectation but the second image has high resolution and in generated pdf there is not half image is there. Also if there is a high resolution image in footer, that footer image also not set properly in PDF file.

@sheoran531994,

Thank you for your feedback. We are investigating this further and will update you as soon as additional information is available.

@sheoran531994,

You can scale images to fit the document size using the code snippet given below.

Document doc = new Document(new ByteArrayInputStream(emlStream.toByteArray()), lo);
// Resize images
resizeImages(doc);
// Save to disc
doc.save( PDFPath, com.aspose.words.SaveFormat.PDF);

private void resizeImages(Document doc) throws Exception {
        int MaxImageWidthInPoints = 450;
        int MaxImageHeightInPoints = 350;
        Node[] shapes = doc.getChildNodes(NodeType.SHAPE, true).toArray();
        for (int i = 0; i < shapes.length; i++) {
            Shape shape = (Shape) shapes[i];
//If images need to be shrunk then scale to fit
            if (shape.getImageData().getImageSize().getWidthPoints() > MaxImageWidthInPoints) {
                double scaleWidth = MaxImageWidthInPoints / shape.getImageData().getImageSize().getWidthPoints();
                double scaleHeight = MaxImageHeightInPoints / shape.getImageData().getImageSize().getHeightPoints();
// Get the smallest scale factor so it will fit on the paper.
                double scaleFactor = Math.min(scaleWidth, scaleHeight);
                shape.setWidth(shape.getImageData().getImageSize().getWidthPoints() * scaleFactor);
                shape.setHeight(shape.getImageData().getImageSize().getHeightPoints() * scaleFactor);
            }
        }
    }

We hope that this answered your question. Please feel free to reach us if additional information is required.

Can you please provide the generated pdf file.

The image in the footer is not properly converted. Please look into the matter.

@sheoran531994,

Thank you for your feedback.
We have attached the sample PDF file generated using the code snippet provided in the previous message.
Photo.pdf (179.7 KB)
According to our understanding, the footer image that you are referring to is the image of a form for creating a new clause. The complete image is visible in the attached PDF file.
In case our understanding of your requirements is not correct, please share a bit more detail regarding the expected output so that we can assist you further.

Hi

I am attaching the email file which contains the footer image which is not converted correctly. Please do the needful.Photo.zip (231.7 KB)

@sheoran531994,

Thank you for your feedback.
We have observed that .msg file was converted fine into .mhtml, but the final PDF output generated by Aspose.Words seemed to have an issue in the footer. Hence, the issue may be related to Aspose.Words API and has been moved to the respective category. We will assist you accordingly in a while.

Thanks for your update.
Please do asap.

@sheoran531994

Thanks for your inquiry. We have tested the scenario using the latest version of Aspose.Words for .NET 18.11 and Aspose.BarCode for .NET 18.11 and noticed that the images are not exported into output PDF. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17776. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi

We are using the aspose.word for java.

@sheoran531994

Thanks for your inquiry. Please note that the latest version of Aspose.Words for Java is completely auto-ported from .NET, i.e. we do not write code for Aspose.Words for Java; it is generated out automatically from C# code of Aspose.Words for .NET. You will get the fix of this issue in Aspose.Words for Java.

Thanks for your update. Please provide the solution asap.

@sheoran531994

Thanks for your inquiry. We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. We work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

Currently, your issue is pending for analysis and is in the queue. Once we complete the analysis of your issue, we will then be able to provide you an estimate.

You reported this issue in free support forum and it will be treated with normal priority. To speed up the progress of issue’s resolution, we suggest you please check our paid support policies from following link.
Paid Support Policies

Thanks for your update.
I have resolved the issue with lot of R&D with the APIs.

@sheoran531994

It is nice to hear from you that your problem has been solved. We will inform you via this forum thread once there is an update available on this issue. We apologize for your inconvenience.