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

Free Support Forum - aspose.com

Extracted TextFragment has wrong rectangle's coorditates

Hi. Founded text fragment “Number” has wrong rectangle coordinates.
Run attached test to reproduce this case.

Source file: Report.pdf (618.6 KB)
Result screen: screen.png (57.9 KB)

Java version: 11
Aspose PDF version: 22.2

	void example() throws IOException {
		var pdfInputStream = new ClassPathResource("pdf/Report.pdf").getInputStream();
		var document = new Document(pdfInputStream);
		var page = document.getPages().get_Item(1);

		var textFragment = findFirstTextFragment(page, "Number");

		var textFragmentRectangle = textFragment.getRectangle();
		var annotationRectangle = page.getAnnotations().get_Item(1).getRectangle(true);

		var transformTextFragmentRectangle = page.getRotationMatrix().reverse().transform(textFragmentRectangle);
		var transformAnnotationRectangle = page.getRotationMatrix().reverse().transform(annotationRectangle);

		drawRectangleOnPage(transformTextFragmentRectangle, page, 1, new SetRGBColorStroke(1, 0,0));
		drawRectangleOnPage(transformAnnotationRectangle, page, 1, new SetRGBColorStroke(0, 0,1));



	public static TextFragment findFirstTextFragment(Page page, String searchValue) {
		var absorber = new TextFragmentAbsorber();

		var textFragments = absorber.getTextFragments();
		if (textFragments.size() != 0) {
			return textFragments.get_Item(1);
		} else {
			return null;

	private static void drawRectangleOnPage(Rectangle rectangle, Page page, int lineWidth, SetRGBColorStroke color) {
		page.getContents().add(new GSave());
		page.getContents().add(new ConcatenateMatrix(1, 0, 0, 1, 0, 0));
		page.getContents().add(new SetLineWidth(lineWidth));
		page.getContents().add(new Re(rectangle.getLLX(), rectangle.getLLY(), rectangle.getWidth(), rectangle.getHeight()));
		page.getContents().add(new ClosePathStroke());
		page.getContents().add(new GRestore());

Am I do something wrong? Have you got any workaround for this issue?


We were able to replicate the issue in our environment while testing the scenario. Therefore, an issue as PDFJAVA-41364 has been logged in our issue tracking system for the sake of correction. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.