Free Support Forum - aspose.com

Avoid Cutting / Distortion of Auto-Fit Table Content during EML MSG or MHTML to PDF File Conversion using Java

Hi,
I have attached the pdf file.

  • PDF- Header logo is not formatted correctly.

  • Content is not converted properly. Some of the information (right side) got cut.

TST2_ITA_AEReporting@pfizer.com_13-01-2021_11-18-20.pdf (223.0 KB)

@ashishyadava,

Could you please also share your sample code (that you are using) and input file (if any), so we could evaluate your issue precisely and help you through.

Due to compliance. I can’t share the actual file and code.
I have raised the concern with manager. once he approve, I will share the file and code.

@ashishyadava

Once you have the approval, please share the source file and working sample code reproducing the issue on your end so that we may help to serve you further.

Please find the source file and sample code.
private void removeAttachmentAndConvertEmlOrMsgFile(int asposeFormat, InputStream docInputStream, OutputStream os,
ByteArrayInputStream licenseFS, String timezone) throws Exception {
MailMessage mailMsg;
ByteArrayOutputStream arrayOutputStream = null;
MhtSaveOptions saveOptions;
com.aspose.email.License emailLicense = new com.aspose.email.License();
emailLicense.setLicense(licenseFS);
mailMsg = MailMessage.load(docInputStream, new EmlLoadOptions());
arrayOutputStream = new ByteArrayOutputStream();
saveOptions = SaveOptions.getDefaultMhtml();
saveOptions.setSaveAttachments(true);
AttachmentCollection attachmentCollection = mailMsg.getAttachments();
if (attachmentCollection != null) {
int size = attachmentCollection.size();
for (int i = 0; i < size; i++) {
Attachment att = attachmentCollection.get_Item(i);
String attFileName = att.getName().replace(":", " “).replace(”\", " “).replace(”/", " “)
.replace(”?", “”).replace(">", “”).replace("<", “”).replace("|", “”);
att.setName(attFileName);
att.setContentStream(new ByteArrayInputStream("".getBytes()));
}
}
mailMsg.setTimeZoneOffset(TimeZone.getTimeZone(timezone).getOffset(mailMsg.getDate().getTime()));
mailMsg.save(arrayOutputStream, saveOptions);
wordLicense(getLicense());
ByteArrayInputStream bis = new ByteArrayInputStream(arrayOutputStream.toByteArray());
com.aspose.words.LoadOptions loadOptions = new com.aspose.words.LoadOptions();
loadOptions.setLoadFormat(com.aspose.words.LoadFormat.MHTML);
com.aspose.words.PdfSaveOptions pso = new PdfSaveOptions();
pso.setJpegQuality(70);
Document doc = new Document(bis, loadOptions);

	// make inline image resize
	@SuppressWarnings("rawtypes")
	NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
	int imageIndex = 0;
	for (Shape shape : (Iterable<Shape>) shapes)
	{
	    if (shape.hasImage() && (shape.getWidth() > 700 || shape.getHeight() > 900))
	    {
	    	double largeDim= shape.getWidth() > shape.getHeight()? shape.getWidth(): shape.getHeight();
	    	double q= shape.getWidth() > shape.getHeight()? 700: 900;
	    	double divExp= q/largeDim;
	        String imageFileName = MessageFormat.format(
	                "Aspose.Images.{0}{1}", imageIndex, com.aspose.words.FileFormatUtil.imageTypeToExtension(shape.getImageData()
	                                .getImageType()));
	        shape.setWidth(shape.getWidth()*divExp);
	        shape.setHeight(shape.getHeight()*divExp);

	        shape.getImageData().save(imageFileName);
	        imageIndex++;
	    }
	}

	doc.save(os, pso);
	//doc.save(os, com.aspose.words.SaveFormat.PDF);
}

Harshavardhan.Gangavarapu@pfizer.com_23-12-2020_20-33-21.zip (94.9 KB)

@ashishyadava

We have converted the MHTML to PDF using latest APIs of Aspose.Words and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-21715. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi,

Can you provide any tentative date or ETA for this issue.

Thanks

@ashishyadava,

The issue depends on the resolution of an internal extremely complex issue (WORDSNET-832). Therefore, WORDSNET-21715 is postponed until at least WORDSNET-832 is resolved, we will review your issue after the resolution of WORDSNET-832. Unfortunately, there is no ETA available at the moment. We will inform you via this forum thread as soon as this issue will get resolved or any further updates may be available in future. We apologize for your inconvenience.