2013-10-30 45 views
1

我正在使用路徑閱讀pdf文件,並且想要向其中添加元數據。將metaData添加到existng pdf文件

我知道添加元數據的方法:

Documnt.addAuthor and ext... 

但我如何讓現有的PDF到文檔對象?

我讀這樣的文件:

PdfReader reader = new PdfReader(pdfFilePath); 
FileOutputStream out = new FileOutputStream(outFile); 
PdfStamper stamp = new PdfStamper(reader, out); 

回答

2

您可以使用:PdfStamper.setMoreInfo

final HashMap<String, String> info = new HashMap<>(); 
if (title != null) { 
    info.put("Title", title); 
} 
if (subject != null) { 
    info.put("Subject", subject); 
} 
if (keywords != null) { 
    info.put("Keywords", keywords); 
} 
if (creator != null) { 
    info.put("Creator", creator); 
} 
if (author != null) { 
    info.put("Author", author); 
} 

stamper.setMoreInfo(info);