How to read the information about setting pdf attributes in Java
pom
<dependency> <groupId></groupId> <artifactId>pdfbox</artifactId> <version>2.0.24</version> </dependency>
Read properties
import ; import ; import ; import ; public class ReadPDFProperties { public static void main(String[] args) { try { // Load PDF file File file = new File(""); PDDocument document = (file); // Get PDF document information PDDocumentInformation info = (); // Read properties String title = (); String author = (); String subject = (); String keywords = (); String creator = (); String producer = (); String creationDate = ().toString(); String modificationDate = ().toString(); String trapped = (); // Output attribute information ("Title: " + title); ("Author: " + author); ("Subject: " + subject); ("Keywords: " + keywords); ("Creator: " + creator); ("Producer: " + producer); ("Creation Date: " + creationDate); ("Modification Date: " + modificationDate); ("Trapped: " + trapped); // Close the document (); } catch (IOException e) { (); } } }
Set properties
import ; import ; import ; import ; public class PDFPropertiesExample { public static void main(String[] args) { try (PDDocument document = (new File(""))) { PDDocumentInformation info = (); // Set document properties ("Author's Name"); ("Document Title"); ("Document Topic"); // More properties can be set, such as: // ("Keyword 1, Keyword 2"); // ("creator application name"); // ("Producer application name"); // Save properties (info); // Save the changed document ("updated_example.pdf"); } catch (IOException e) { (); } } }
This is the article about Java implementation of reading and setting pdf attribute information. For more information about Java reading and setting pdf attribute information, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!