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

Free Support Forum - aspose.com

How to crop the image in the generated pdf to display?

In the use of aspose.word to convert HTML to pdf, if the image is too high, it will be a line feed to the next page to display, how to crop the image in the generated pdf to display?

I don’t know how to express clearly in words, please take a look at the picture I uploaded.

C# 、Aspose.word、the latest dll、Which API is used?

888.png (71.4 KB)
999.png (83.6 KB)

@Northman There is not built in way to achieve this, since image is not flow content. To achieve what you need you should have two copies of the same shape with different cropping.
You can crop the image using ImageData.CropBottom, ImageData.CropLeft, ImageData.CropTop, ImageData.CropRight properties. For example, see the following code, which inserts an image two times and crop one part from bottom another part from top:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape image1 = builder.InsertImage(@"C:\Temp\test.png");
Shape image2 = builder.InsertImage(@"C:\Temp\test.png");

image1.ImageData.CropBottom = 0.3;
// AspectRatioLocked should be unlocked so the change of shape height does not affect its width.
image1.AspectRatioLocked = false;
// Decrease shape height according to the crop value.
image1.Height = image1.Height * 0.7;

image2.ImageData.CropTop = 0.7;
image2.AspectRatioLocked = false;
image2.Height = image2.Height * 0.3;


In your case, if the image is inline, you can clone the image for example 10 times, crop them so the each shape represent a 10% stripe of the original image and put them into separate paragraphs one after another. In this case layout engine will move stripes to the next page if they does not fit the page height.

Thank you very much for your reply, I have understood, but this approach is not the effect I want, of course, I found a better way to achieve, and finally, thank you very much for this idea, not bad ~

@Northman It is perfect that you managed to achieve what you need.