Free Support Forum - aspose.com

Image truncation issue

Image got truncated from right side. we had converting the html file to pdf file.
I’m attaching the html file and converted pdf file.tarun.srivastava@genpact.digital_27-11-2020_07-18-20.pdf (175.5 KB)FW_ Issue 704.zip (252.9 KB)

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);
	}

@ashishyadava

After working with sample code and source file provided by you, it seems to be an issue related to Aspose.Email while truncating the right side image when saving to MHTML. A ticket with ID EMAILJAVA-34784 has bee created to further investigate and resolve the issue.

You have shared MSG file where as you are using EmlLoadOptions(). You need to use MsgLoadOptions() for MSG file. Is this the case with you in another thread where you have reported InvalidOperation Exception issue?

Thanks for update. We are reading the outlook and process the eml file for conversion.
If I used below code than it’s correct right?
mailMsg = MailMessage.load(docInputStream, new EmlLoadOptions());

I have the eml file that causing the InvalidOperarion exception issue. If you want, I can share with you.docset_pvai_10378803.zip (34.4 KB)

@ashishyadava

There is no InvalidOperarion exception issue with the new file shared by you as well on our end. I have shared the output and used sample code with you for this in another thread as well where you have shared the same thing.

TestEmail.java.zip (2.1 KB)

Hi,

Can you provide any tentative date or ETA for issue EMAILJAVA-34784.

Thanks
Ashish

@ashishyadava

I regret to share that at present the issue is still unresolved and we request for your patience. We will share the good news with you as soon as the issue will be addressed.