Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
Copy PDF Document with iText
How to copy PDF document using iText Java Library?
✍: FYIcenter.com
Here is a tutorial for copying PDF document and update it's information
using iText Java Library.
1. Create a Java file, PdfUpdate.java:
/**
* Copy PDF and update info
*/
import com.itextpdf.kernel.pdf.*;
import java.io.*;
public class PdfUpdate {
public static void main(String args[]) throws IOException {
PdfReader reader = new PdfReader(args[0]);
PdfWriter writer = new PdfWriter(args[1]);
PdfDocument pdf = new PdfDocument(reader, writer);
PdfDocumentInfo info = pdf.getDocumentInfo();
System.out.println("Title: "+info.getTitle());
System.out.println("Author: "+info.getAuthor());
System.out.println("Subject: "+info.getSubject());
System.out.println("Creator: "+info.getCreator());
System.out.println("Producer: "+info.getProducer());
info.setAuthor("FYIcenter.com");
info.setSubject("Test on updating PDF info");
// info.setProducer("iText7");
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 \ PdfUpdate.java hello.pdf updated.pdf Title: null Subject: null Keywords: null Author: null Creator: null Producer: iText® 7.1.4 ©2000-2018 iText Group NV (AGPL-version); \ modified using iText® 7.1.4 ©2000-2018 iText Group NV (AGPL-version)
3. Check the updated PDF: updated.pdf.
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 updated.pdf Title: null Subject: Test on updating PDF info Keywords: null Author: FYIcenter.com Creator: null Producer: iText® 7.1.4 ©2000-2018 iText Group NV (AGPL-version); \ modified using iText® 7.1.4 ©2000-2018 iText Group NV (AGPL-version)
Note that iText7 does not allow to set "Producer" field.
⇒ Where to save iText-5.0.1.jar to make compiler happy
⇐ Get PDF Document Info with iText
2021-11-13, ∼2196🔥, 0💬
Popular Posts:
Xalan-Java, Version 2.7.1, is an XSLT processor for transforming XML documents into HTML, text, or o...
JDK 17 java.rmi.jmod is the JMOD file for JDK 17 RMI (Remote Method Invocation) module. JDK 17 RMI m...
JDK 17 java.base.jmod is the JMOD file for JDK 17 Base module. JDK 17 Base module compiled class fil...
How to download and install iText7-Core-7.1.4.zip? iText7-Core-7.1.4.zip is the binary package of iT...
What Is junit-3.8.1.jar? junit-3.8.1.jar is the version 3.8.1 of JUnit JAR library file. JUnit is a ...