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