Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,45 @@ public DublinCoreSchema() {
}

/**
* Adds a title.
* Adds a title for {@link LangAlt#DEFAULT default language}.
*
* @param title title
*/
public void addTitle(String title) {
XmpArray array = new XmpArray(XmpArray.ALTERNATIVE);
array.add(title);
setProperty(TITLE, array);
addTitle(LangAlt.DEFAULT, title);
}

/**
* Adds a description.
* Adds a title for specified language.
*
* @param language language
* @param title title
*/
public void addTitle(String language, String title) {
LangAlt langAlt = new LangAlt();
langAlt.addLanguage(language, title);
setProperty(TITLE, langAlt);
}

/**
* Adds a description for {@link LangAlt#DEFAULT default language}.
*
* @param desc description
*/
public void addDescription(String desc) {
XmpArray array = new XmpArray(XmpArray.ALTERNATIVE);
array.add(desc);
setProperty(DESCRIPTION, array);
addDescription(LangAlt.DEFAULT, desc);
}

/**
* Adds a description for specified language.
*
* @param language language
* @param desc description
*/
public void addDescription(String language, String desc) {
LangAlt langAlt = new LangAlt();
langAlt.addLanguage(language, desc);
setProperty(DESCRIPTION, langAlt);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class PdfSchema extends XmpSchema {
/**
* Keywords.
*/
public static final String KEYWORDS = "pdf:keywords";
public static final String KEYWORDS = "pdf:Keywords";
/**
* The PDF file version (for example: 1.0, 1.3, and so on).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfDictionary;
import com.lowagie.text.pdf.PdfName;
import com.lowagie.text.pdf.PdfString;
import com.lowagie.text.pdf.PdfWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -24,11 +27,32 @@
public class PDFValidationTest {

@Test
public void testValidatePDFWithVera() throws Exception {
public void testValidateDcTitleWithVera() throws Exception {
PdfDictionary info = new PdfDictionary(PdfName.METADATA);
info.put(PdfName.TITLE, new PdfString("Test pdf"));
Assertions.assertTrue(testValidatePDFWithVera(info));
}

@Test
public void testValidateDcSubjectWithVera() throws Exception {
PdfDictionary info = new PdfDictionary(PdfName.METADATA);
info.put(PdfName.SUBJECT, new PdfString("Test subject"));
Assertions.assertTrue(testValidatePDFWithVera(info));
}

@Test
public void testValidatePdfKeywordsWithVera() throws Exception {
PdfDictionary info = new PdfDictionary(PdfName.METADATA);
info.put(PdfName.KEYWORDS, new PdfString("k1, k2"));
Assertions.assertTrue(testValidatePDFWithVera(info));
}

private boolean testValidatePDFWithVera(PdfDictionary info) throws Exception {
Document document = new Document(PageSize.A4);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
PdfWriter pdfWriter = PdfWriter.getInstance(document, byteArrayOutputStream);
pdfWriter.setPDFXConformance(PdfWriter.PDFA1B);
pdfWriter.getInfo().putAll(info);
pdfWriter.createXmpMetadata();

try {
Expand Down Expand Up @@ -58,10 +82,11 @@ public void testValidatePDFWithVera() throws Exception {
}

}
Assertions.assertTrue(result.isCompliant());
return result.isCompliant();
}
} catch (ModelParsingException e) {
e.printStackTrace();
return false;
}
}

Expand Down