Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

itext and extract page coordinates

Featured Replies

I have a scanned PDF that has multiple areas of text handwritten text. I want to see if there's a way in itext to extrapolate coordinates on the page to be inserted into separate Container or viewers. Such as did this person sign the document? show the last 2 inches of the page starting 3 inches from the left.

Bear in mind that the iText co-ordinate system starts bottom left, like a graph and 72dpi

Two way to do it spring to mind

A: Copy the file and just make the crop box to the size of what you want left to display, leaves the whole file there just not visible

B: Render the file to an image and then use a java awt transformation to just get the part you want. (This could in part be done in FM12 with the Get (Thumbnail) function)

The first one is really easy


import com.itextpdf.text.pdf.PdfDictionary

import com.itextpdf.text.pdf.PdfName

import com.itextpdf.text.pdf.PdfReader

import com.itextpdf.text.pdf.PdfRectangle

import com.itextpdf.text.pdf.PdfStamper



reader = new PdfReader(src)



// make this 'lower left' 3in along, 0 up TO 'upper right' pageWidth along 2in up

PdfRectangle rect = new PdfRectangle(216, 0, reader.getPageSize(1).getWidth(), 144)



// for ALL pages use this

n = reader.getNumberOfPages()

for (i in 1..<n) {

pageDict = reader.getPageN(i)

pageDict.put(PdfName.CROPBOX, rect)

}

// or for just ONE known page

//pageDict = reader.getPageN(1)

//pageDict.put(PdfName.CROPBOX, rect



stamper = new PdfStamper(reader, new FileOutputStream(dest))

stamper.close()



Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.