Problem Description:
Using iText java to create PDF with meta-data values as follows. PDF created successfully however the meta-data values are empty or blank.
Document document = new Document(PageSize.A4, -55, -65, 20, 7);
document.addAuthor("pdfAuthor");
document.addCreator("pdfCreator");
document.addCreationDate();
document.addTitle("Title");
document.addSubject("Subject");
document.addKeywords("Keywords");
PdfWriter writer = null;
ByteArrayOutputStream byteOut = null;
byteOut = new ByteArrayOutputStream();
writer = PdfWriter.getInstance(document, byteOut);
document.open();
Solution:
Always add document meta-data after creating the PdfWriter Instance. So move the highlighted codes below PdfWriter.getInstance.
Document document = new Document(PageSize.A4, -55, -65, 20, 7);
PdfWriter writer = null;
ByteArrayOutputStream byteOut = null;
byteOut = new ByteArrayOutputStream();
writer = PdfWriter.getInstance(document, byteOut);
document.addAuthor("pdfAuthor");
document.addCreator("pdfCreator");
document.addCreationDate();
document.addTitle("Title");
document.addSubject("Subject");
document.addKeywords("Keywords");
document.open();
Using iText java to create PDF with meta-data values as follows. PDF created successfully however the meta-data values are empty or blank.
Document document = new Document(PageSize.A4, -55, -65, 20, 7);
document.addAuthor("pdfAuthor");
document.addCreator("pdfCreator");
document.addCreationDate();
document.addTitle("Title");
document.addSubject("Subject");
document.addKeywords("Keywords");
PdfWriter writer = null;
ByteArrayOutputStream byteOut = null;
byteOut = new ByteArrayOutputStream();
writer = PdfWriter.getInstance(document, byteOut);
document.open();
Solution:
Always add document meta-data after creating the PdfWriter Instance. So move the highlighted codes below PdfWriter.getInstance.
Document document = new Document(PageSize.A4, -55, -65, 20, 7);
PdfWriter writer = null;
ByteArrayOutputStream byteOut = null;
byteOut = new ByteArrayOutputStream();
writer = PdfWriter.getInstance(document, byteOut);
document.addAuthor("pdfAuthor");
document.addCreator("pdfCreator");
document.addCreationDate();
document.addTitle("Title");
document.addSubject("Subject");
document.addKeywords("Keywords");
document.open();
No comments:
Post a Comment