Get PDF Document Info with iText

Q

How to get PDF document information using iText Java Library?

✍: FYIcenter.com

A

Here is a tutorial for getting PDF document information using iText Java Library.

1. Create a Java file, PdfInfo.java:

/**
 * Get PDF info
 */
import com.itextpdf.kernel.pdf.*;
import java.io.*;

public class PdfInfo {
  public static void main(String args[]) throws IOException {
    PdfReader reader = new PdfReader(args[0]);
    PdfDocument pdf = new PdfDocument(reader);
    PdfDocumentInfo info = pdf.getDocumentInfo();
    System.out.println("Title: "+info.getTitle());
    System.out.println("Subject: "+info.getSubject());
    System.out.println("Keywords: "+info.getKeywords());
    System.out.println("Author: "+info.getAuthor());
    System.out.println("Creator: "+info.getCreator());
    System.out.println("Producer: "+info.getProducer());
    pdf.close();
  }
}

2. Run the Java program iText 7 Java Library.

fyicenter$ java -cp java -cp kernel-7.1.4.jar:layout-7.1.4.jar: \
  io-7.1.4.jar:slf4j-api-1.7.31.jar \
  PdfInfo.java hello.pdf

Title: null
Subject: null
Keywords: null
Author: null
Creator: null
Producer: iText® 7.1.4 ©2000-2018 iText Group NV (AGPL-version)

3. View the output. You see only the "Producer" field value on the PDF file: hello.pdf.

 

Copy PDF Document with iText

Draw Shape in PDF with iText

Using iText Library in Java Programs

⇑⇑ iText for PDF Generation

2021-11-13, 880🔥, 0💬