An Interest In:
Web News this Week
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
April 1, 2022 06:52 am GMT
Original Link: https://dev.to/carlwils/java-get-coordinates-of-images-in-pdf-go
Java/ Get Coordinates of Images in PDF
PDF is one of the most popular and compatible file format created by Adobe in the 1900s, and a PDF can contain text, images, hyperlinks, tables, etc. Sometimes you may need to get the x and y coordinates of images in a PDF page to get their precise locations. In this article, you will learn how to accomplish this task in Java using Free Spire.PDF for Java.
Install the Free Library (2 Methods)
Method 1: Download the free library and unzip it. Then add the Spire.Pdf.jar file to your Java application as dependency.
Method 2: Directly add the jar dependency to maven project by adding the following configurations to the pom.xml file.
<repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url> </repository></repositories><dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.pdf.free</artifactId> <version>5.1.0</version> </dependency></dependencies>
Sample Code
import com.spire.pdf.PdfDocument;import com.spire.pdf.PdfPageBase;import com.spire.pdf.exporting.PdfImageInfo;import java.awt.geom.Rectangle2D;public class GetCoordinateOfImage { public static void main(String[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Load a PDF file doc.loadFromFile("file1.pdf"); //Get the first worksheet PdfPageBase page = doc.getPages().get(0); //Get the image information of the page PdfImageInfo[] imageInfo = page.getImagesInfo(); //Loop through the image information for (int i = 0; i < imageInfo.length; i++) { //Get the bounds property of a specific image Rectangle2D rect = imageInfo[i].getBounds(); //Get the x and y coordinates System.out.println(String.format("The coordinate of image %d:%f, %f", i+1, rect.getX(), rect.getY())); } }}
Original Link: https://dev.to/carlwils/java-get-coordinates-of-images-in-pdf-go
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To