Custom Metadata entry

This is a code example of iText PDF, discover more.

31st May 2016
admin-marketing

Switch code for this example

CustomMetaEntry.java
  1. /*
  2.  
  3.     This file is part of the iText (R) project.
  4.     Copyright (c) 1998-2016 iText Group NV
  5.  
  6. */
  7.  
  8. /**
  9.  * This example is written by Bruno Lowagie in answer to the following question:
  10.  * http://stackoverflow.com/questions/26726485/itext-add-delete-retrieve-information-in-custom-property
  11.  */
  12. package com.itextpdf.samples.sandbox.objects;
  13.  
  14. import com.itextpdf.kernel.pdf.PdfDocument;
  15. import com.itextpdf.kernel.pdf.PdfWriter;
  16. import com.itextpdf.layout.Document;
  17. import com.itextpdf.layout.element.Paragraph;
  18. import com.itextpdf.samples.GenericTest;
  19. import com.itextpdf.test.annotations.type.SampleTest;
  20.  
  21. import org.junit.experimental.categories.Category;
  22.  
  23. import java.io.File;
  24. import java.io.IOException;
  25.  
  26. @Category(SampleTest.class)
  27. public class CustomMetaEntry extends GenericTest {
  28.     public static final String DEST = "./target/test/resources/sandbox/objects/custom_meta_entry.pdf";
  29.  
  30.     public static void main(String[] args) throws IOException {
  31.         File file = new File(DEST);
  32.         file.getParentFile().mkdirs();
  33.         new CustomMetaEntry().manipulatePdf(DEST);
  34.     }
  35.  
  36.     public void manipulatePdf(String dest) throws IOException {
  37.         PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
  38.         Document doc = new Document(pdfDoc);
  39.  
  40.         pdfDoc.getDocumentInfo().setTitle("Some example");
  41.         pdfDoc.getDocumentInfo().setMoreInfo("Test", "test");
  42.  
  43.         Paragraph p = new Paragraph("Hello World");
  44.  
  45.         doc.add(p);
  46.  
  47.         doc.close();
  48.     }
  49. }
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now