Reputation: 55
I am able to extract PDF properties using java code as below: But i am confused how to get [Format like "PDF1.3" and page Size like"A4, Portrait (210 × 297 mm)"] properties using java code.
System.out.println(file.getName());
PdfReader reader = new PdfReader(file.toString());
HashMap<String, String> info = reader.getInfo();
char info1=reader.getPdfVersion();
byte[] b1 = reader.getMetadata();
System.out.println(info);
System.out.println(info1);
I have tried PDFbox API also, but i cant find the method for the same, Is it possible to fetch the following properties using java (i am using ubuntu)
ScreenShot of what i wanted to extract:
Upvotes: 0
Views: 4051
Reputation: 5940
You can get document information using PDDocument
class in PDFBox api
. PDDocumentInformation
is used to retrieve author, version, created date, updated date, etc features.
PDDocument doc = PDDocument.load(new File(filePath));
PDDocumentInformation info = doc.getDocumentInformation();
String author = info.getAuthor();
int pages = doc.getNumberOfPages();
// String creator = info.getCreator();
Calendar calendar = info.getCreationDate();
System.out.println("Author : " + author);
System.out.println("Created : " + new SimpleDateFormat("dd-MM-yyyy hh:mm:ss aa").format(calendar.getTimeInMillis()));
System.out.println("Total Pages : " + pages);
if(pages > 0) {
float width = doc.getPage(0).getMediaBox().getWidth();
float height = doc.getPage(0).getMediaBox().getHeight();
System.out.println("Page 0 size : " + width + " * " + height);
} else {
System.err.println("No pages.");
}
Here is link to Get Page Format.
Here is link to Get Page information and Author.
Hope it'll help.
Upvotes: 1