Custom Metadata entry

25th October 2015
admin-marketing

Switch code for this example

CustomMetaEntry.java
  1. /**
  2.  * This example is written by Bruno Lowagie in answer to the following question:
  3.  * http://stackoverflow.com/questions/26726485/itext-add-delete-retrieve-information-in-custom-property
  4.  */
  5. package sandbox.objects;
  6.  
  7. import com.itextpdf.text.Document;
  8. import com.itextpdf.text.DocumentException;
  9. import com.itextpdf.text.Header;
  10. import com.itextpdf.text.Paragraph;
  11. import com.itextpdf.text.pdf.PdfWriter;
  12.  
  13. import java.io.File;
  14. import java.io.FileOutputStream;
  15. import java.io.IOException;
  16. import sandbox.WrapToTest;
  17.  
  18. @WrapToTest
  19. public class CustomMetaEntry {
  20.  
  21.     public static final String DEST = "results/objects/custom_meta.pdf";
  22.    
  23.     public static void main(String[] args) throws IOException,
  24.             DocumentException {
  25.         File file = new File(DEST);
  26.         file.getParentFile().mkdirs();
  27.         new CustomMetaEntry().createPdf(DEST);
  28.     }
  29.    
  30.     public void createPdf(String dest) throws IOException, DocumentException {
  31.         Document document = new Document();
  32.         PdfWriter.getInstance(document, new FileOutputStream(dest));
  33.         document.addTitle("Some example");
  34.         document.add(new Header("Test", "test"));
  35.         document.open();
  36.         Paragraph p = new Paragraph("Hello World");
  37.         document.add(p);
  38.         document.close();
  39.     }
  40.    
  41. }
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