Java實(shí)現(xiàn)讀取設(shè)置pdf屬性信息
Java如何讀取設(shè)置pdf屬性信息
pom
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.24</version>
</dependency>
讀取屬性
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
import java.io.File;
import java.io.IOException;
public class ReadPDFProperties {
public static void main(String[] args) {
try {
// 加載PDF文件
File file = new File("example.pdf");
PDDocument document = PDDocument.load(file);
// 獲取PDF文檔信息
PDDocumentInformation info = document.getDocumentInformation();
// 讀取屬性
String title = info.getTitle();
String author = info.getAuthor();
String subject = info.getSubject();
String keywords = info.getKeywords();
String creator = info.getCreator();
String producer = info.getProducer();
String creationDate = info.getCreationDate().toString();
String modificationDate = info.getModificationDate().toString();
String trapped = info.getTrapped();
// 輸出屬性信息
System.out.println("Title: " + title);
System.out.println("Author: " + author);
System.out.println("Subject: " + subject);
System.out.println("Keywords: " + keywords);
System.out.println("Creator: " + creator);
System.out.println("Producer: " + producer);
System.out.println("Creation Date: " + creationDate);
System.out.println("Modification Date: " + modificationDate);
System.out.println("Trapped: " + trapped);
// 關(guān)閉文檔
document.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
設(shè)置屬性
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
import java.io.File;
import java.io.IOException;
public class PDFPropertiesExample {
public static void main(String[] args) {
try (PDDocument document = PDDocument.load(new File("example.pdf"))) {
PDDocumentInformation info = document.getDocumentInformation();
// 設(shè)置文檔屬性
info.setAuthor("作者姓名");
info.setTitle("文檔標(biāo)題");
info.setSubject("文檔主題");
// 可以設(shè)置更多屬性,例如:
// info.setKeywords("關(guān)鍵詞1, 關(guān)鍵詞2");
// info.setCreator("創(chuàng)建者應(yīng)用名");
// info.setProducer("生產(chǎn)者應(yīng)用名");
// 保存屬性
document.setDocumentInformation(info);
// 保存更改后的文檔
document.save("updated_example.pdf");
} catch (IOException e) {
e.printStackTrace();
}
}
}
到此這篇關(guān)于Java實(shí)現(xiàn)讀取設(shè)置pdf屬性信息的文章就介紹到這了,更多相關(guān)Java讀取設(shè)置pdf屬性信息內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue中computed計(jì)算屬性和data數(shù)據(jù)獲取方式
這篇文章主要介紹了Vue中computed計(jì)算屬性和data數(shù)據(jù)獲取方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03
Spark?Streaming?內(nèi)部運(yùn)行機(jī)制示例詳解
這篇文章主要介紹了Spark?Streaming?內(nèi)部運(yùn)行機(jī)制示例詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2025-05-05
SpringBoot整合InfluxDB的詳細(xì)過(guò)程
InfluxDB是一個(gè)開源的時(shí)間序列數(shù)據(jù)庫(kù),由Go語(yǔ)言編寫,適用于存儲(chǔ)和查詢按時(shí)間順序產(chǎn)生的數(shù)據(jù),它具有高效的數(shù)據(jù)存儲(chǔ)和查詢機(jī)制,支持高并發(fā)寫入和查詢,靈活的數(shù)據(jù)模型和強(qiáng)大的查詢語(yǔ)言,本文介紹SpringBoot整合InfluxDB的詳細(xì)過(guò)程,感興趣的朋友一起看看吧2024-12-12
Spring創(chuàng)建Bean的多種方式對(duì)比與最佳實(shí)踐
本文詳細(xì)梳理了Spring項(xiàng)目中Bean的六種常見創(chuàng)建方式(@Component、@Bean、FactoryBean、@Import、XML、運(yùn)行時(shí)注冊(cè)),對(duì)每種適用場(chǎng)景、優(yōu)缺點(diǎn)與最佳實(shí)踐進(jìn)行了總結(jié),并給出了選擇方法的決策清單與常見誤區(qū)規(guī)避建議,需要的朋友可以參考下2025-10-10
Spring Data JPA 之 JpaRepository的使用
這篇文章主要介紹了Spring Data JPA 之 JpaRepository的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02
性能爆棚的實(shí)體轉(zhuǎn)換復(fù)制工具M(jìn)apStruct使用詳解
這篇文章主要為大家介紹了性能爆棚的實(shí)體轉(zhuǎn)換復(fù)制工具M(jìn)apStruct使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03

