com.lowagie.text.pdf.PdfDate Java Examples

The following examples show how to use com.lowagie.text.pdf.PdfDate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PdfCollectionField.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Returns a PdfObject that can be used as the value of a Collection Item.
 * @param v	value	the value that has to be changed into a PdfObject (PdfString, PdfDate or PdfNumber)	
 */
public PdfObject getValue(String v) {
	switch(fieldType) {
	case TEXT:
		return new PdfString(v, PdfObject.TEXT_UNICODE);
	case DATE:
		return new PdfDate(PdfDate.decode(v));
	case NUMBER:
		return new PdfNumber(v);
	}
	throw new IllegalArgumentException(v + " is not an acceptable value for the field " + get(PdfName.N).toString());
}
 
Example #2
Source File: PdfCollectionItem.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Sets the value of the collection item.
 * @param d
 */
public void addItem(String key, PdfDate d) {
	PdfName fieldname = new PdfName(key);
	PdfCollectionField field = (PdfCollectionField)schema.get(fieldname);
	if (field.fieldType == PdfCollectionField.DATE) {
		put(fieldname, d);
	}
}
 
Example #3
Source File: PdfCollectionField.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns a PdfObject that can be used as the value of a Collection Item.
 * @param v	value	the value that has to be changed into a PdfObject (PdfString, PdfDate or PdfNumber)	
 */
public PdfObject getValue(String v) {
	switch(fieldType) {
	case TEXT:
		return new PdfString(v, PdfObject.TEXT_UNICODE);
	case DATE:
		return new PdfDate(PdfDate.decode(v));
	case NUMBER:
		return new PdfNumber(v);
	}
	throw new IllegalArgumentException(v + " is not an acceptable value for the field " + get(PdfName.N).toString());
}
 
Example #4
Source File: PdfCollectionItem.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Sets the value of the collection item.
 * @param d
 */
public void addItem(String key, PdfDate d) {
	PdfName fieldname = new PdfName(key);
	PdfCollectionField field = (PdfCollectionField)schema.get(fieldname);
	if (field.fieldType == PdfCollectionField.DATE) {
		put(fieldname, d);
	}
}
 
Example #5
Source File: ITextPdfDict.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Date getDateValue(String name) {
	PdfObject pdfObject = wrapped.get(new PdfName(name));
	PdfString s = (PdfString) pdfObject;
	if (s == null) {
		return null;
	}
	return PdfDate.decode(s.toString()).getTime();
}
 
Example #6
Source File: XmpWriter.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * @param os
 * @param info
 * @throws IOException
 */
public XmpWriter(OutputStream os, Map info) throws IOException {
    this(os);
    if (info != null) {
    	DublinCoreSchema dc = new DublinCoreSchema();
    	PdfSchema p = new PdfSchema();
    	XmpBasicSchema basic = new XmpBasicSchema();
    	String key;
    	String value;
    	for (Iterator it = info.entrySet().iterator(); it.hasNext();) {
    		Map.Entry entry = (Map.Entry) it.next();
    		key = (String) entry.getKey();
    		value = (String) entry.getValue();
    		if (value == null)
    			continue;
    		if ("Title".equals(key)) {
    			dc.addTitle(value);
    		}
    		if ("Author".equals(key)) {
    			dc.addAuthor(value);
    		}
    		if ("Subject".equals(key)) {
    			dc.addSubject(value);
    			dc.addDescription(value);
    		}
    		if ("Keywords".equals(key)) {
    			p.addKeywords(value);
    		}
    		if ("Creator".equals(key)) {
    			basic.addCreatorTool(value);
    		}
    		if ("Producer".equals(key)) {
    			p.addProducer(value);
    		}
    		if ("CreationDate".equals(key)) {
    			basic.addCreateDate(PdfDate.getW3CDate(value));
    		}
    		if ("ModDate".equals(key)) {
    			basic.addModDate(PdfDate.getW3CDate(value));
    		}
    	}
    	if (dc.size() > 0) addRdfDescription(dc);
    	if (p.size() > 0) addRdfDescription(p);
    	if (basic.size() > 0) addRdfDescription(basic);
    }
}
 
Example #7
Source File: XmpWriter.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @param os
 * @param info
 * @throws IOException
 */
public XmpWriter(OutputStream os, Map info) throws IOException {
    this(os);
    if (info != null) {
    	DublinCoreSchema dc = new DublinCoreSchema();
    	PdfSchema p = new PdfSchema();
    	XmpBasicSchema basic = new XmpBasicSchema();
    	String key;
    	String value;
    	for (Iterator it = info.entrySet().iterator(); it.hasNext();) {
    		Map.Entry entry = (Map.Entry) it.next();
    		key = (String) entry.getKey();
    		value = (String) entry.getValue();
    		if (value == null)
    			continue;
    		if ("Title".equals(key)) {
    			dc.addTitle(value);
    		}
    		if ("Author".equals(key)) {
    			dc.addAuthor(value);
    		}
    		if ("Subject".equals(key)) {
    			dc.addSubject(value);
    			dc.addDescription(value);
    		}
    		if ("Keywords".equals(key)) {
    			p.addKeywords(value);
    		}
    		if ("Creator".equals(key)) {
    			basic.addCreatorTool(value);
    		}
    		if ("Producer".equals(key)) {
    			p.addProducer(value);
    		}
    		if ("CreationDate".equals(key)) {
    			basic.addCreateDate(PdfDate.getW3CDate(value));
    		}
    		if ("ModDate".equals(key)) {
    			basic.addModDate(PdfDate.getW3CDate(value));
    		}
    	}
    	if (dc.size() > 0) addRdfDescription(dc);
    	if (p.size() > 0) addRdfDescription(p);
    	if (basic.size() > 0) addRdfDescription(basic);
    }
}
 
Example #8
Source File: PdfXmpCreator.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
byte[] createXmpMetadata()
{
	try
	{
		XMPMeta xmp = XMPMetaFactory.create();
		xmp.setObjectName("");

		xmp.setProperty(XMPConst.NS_DC, DublinCoreSchema.FORMAT, FORMAT_PDF);
		xmp.setProperty(XMPConst.NS_PDF, PDF_PRODUCER, Document.getVersion());

		if (pdfWriter.getPDFXConformance() == PdfWriter.PDFA1A)
		{
			xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_PART, PDFA_PART_1);
			xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_CONFORMANCE, PDFA_CONFORMANCE_A);
		}
		else if (pdfWriter.getPDFXConformance() == PdfWriter.PDFA1B)
		{
			xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_PART, PDFA_PART_1);
			xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_CONFORMANCE, PDFA_CONFORMANCE_B);
		}

		xmp.setProperty(XMPConst.NS_XMP, XMP_CREATE_DATE, ((PdfDate) info.get(PdfName.CREATIONDATE)).getW3CDate());
		xmp.setProperty(XMPConst.NS_XMP, XMP_MODIFY_DATE, ((PdfDate) info.get(PdfName.MODDATE)).getW3CDate());

		String title = extractInfo(PdfName.TITLE);
		if (title != null)
		{
			xmp.setLocalizedText(XMPConst.NS_DC, DublinCoreSchema.TITLE, 
					//FIXME use the tag language?
					XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, title);
		}

		String author = extractInfo(PdfName.AUTHOR);
		if (author != null)
		{
			//FIXME cache the options?
			PropertyOptions arrayOrdered = new PropertyOptions().setArrayOrdered(true);
			xmp.appendArrayItem(XMPConst.NS_DC, DublinCoreSchema.CREATOR, arrayOrdered, author, null);
		}

		String subject = extractInfo(PdfName.SUBJECT);
		if (subject != null)
		{
			PropertyOptions array = new PropertyOptions().setArray(true);
			xmp.appendArrayItem(XMPConst.NS_DC, DublinCoreSchema.SUBJECT, array, subject, null);
			xmp.setLocalizedText(XMPConst.NS_DC, DublinCoreSchema.DESCRIPTION, 
					XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, subject);
		}

		String keywords = extractInfo(PdfName.KEYWORDS);
		if (keywords != null)
		{
			xmp.setProperty(XMPConst.NS_PDF, PDF_KEYWORDS, keywords);
		}

		String creator = extractInfo(PdfName.CREATOR);
		if (creator != null)
		{
			xmp.setProperty(XMPConst.NS_XMP, XMP_CREATOR_TOOL, creator);
		}

		SerializeOptions options = new SerializeOptions();
		options.setUseCanonicalFormat(true);

		ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
		XMPMetaFactory.serialize(xmp, out, options);
		return out.toByteArray();
	}
	catch (XMPException e)
	{
		throw new JRRuntimeException(e);
	}
}
 
Example #9
Source File: PdfCollectionItem.java    From gcs with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Sets the value of the collection item.
 * @param c
 */
public void addItem(String key, Calendar c) {
	addItem(key, new PdfDate(c));
}
 
Example #10
Source File: PdfCollectionItem.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Sets the value of the collection item.
 * @param c
 */
public void addItem(String key, Calendar c) {
	addItem(key, new PdfDate(c));
}