Example usage for com.lowagie.text.xml.xmp XmpWriter addRdfDescription

List of usage examples for com.lowagie.text.xml.xmp XmpWriter addRdfDescription

Introduction

In this page you can find the example usage for com.lowagie.text.xml.xmp XmpWriter addRdfDescription.

Prototype

public void addRdfDescription(XmpSchema s) throws IOException 

Source Link

Document

Adds an rdf:Description.

Usage

From source file:de.unigoettingen.sub.commons.contentlib.pdflib.PDFManager.java

License:Apache License

/**
 * Write xmp metadata./*from   w  ww . ja  va 2 s.  c om*/
 * 
 * @param inWriter the in writer
 */
private void writeXMPMetadata(PdfWriter inWriter) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();

    try {
        XmpWriter xmp = new XmpWriter(os);
        XmpSchema dc = new DublinCoreSchema();

        // set DublinCore metadata
        if (this.subject != null) {
            dc.setProperty(DublinCoreSchema.SUBJECT, this.subject);
        }
        if (this.title != null) {
            dc.setProperty(DublinCoreSchema.TITLE, this.title);
        }
        if (this.author != null) {
            dc.setProperty(DublinCoreSchema.CREATOR, this.author);
        }

        // add the DublinCore Simple Metadata to the RDF container

        xmp.addRdfDescription(dc);

        PdfSchema pdf = new PdfSchema();
        // set keywords
        pdf.setProperty(PdfSchema.KEYWORDS, "Hello World, XMP, Metadata");

        // set the version; must be 1.4 for PDF/A
        pdf.setProperty(PdfSchema.VERSION, "1.4");
        xmp.addRdfDescription(pdf);

        xmp.close();
    } catch (IOException e) {
        LOGGER.error("error occured while writing xmp metadata", e);
    }
    inWriter.setXmpMetadata(os.toByteArray());
}

From source file:org.alchemy.core.AlcSession.java

License:Open Source License

/** Save the canvas to a single paged PDF file
 * //from   www . j  a  v  a 2 s . co  m
 * @param file  The file object to save the pdf to
 * @return      True if save worked, otherwise false
 */
boolean saveSinglePdf(File file) {
    // Get the current 'real' size of the canvas without margins/borders
    java.awt.Rectangle bounds = Alchemy.canvas.getVisibleRect();
    //int singlePdfWidth = Alchemy.window.getWindowSize().width;
    //int singlePdfHeight = Alchemy.window.getWindowSize().height;
    com.lowagie.text.Document document = new com.lowagie.text.Document(
            new com.lowagie.text.Rectangle(bounds.width, bounds.height), 0, 0, 0, 0);
    System.out.println("Save Single Pdf Called: " + file.toString());
    boolean noError = true;

    try {

        PdfWriter singleWriter = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.addTitle("Alchemy Session");
        document.addAuthor(USER_NAME);
        document.addCreator("Alchemy <http://al.chemy.org>");

        // Add metadata and open the document
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XmpWriter xmp = new XmpWriter(os);
        PdfSchema pdf = new PdfSchema();
        pdf.setProperty(PdfSchema.KEYWORDS, "Alchemy <http://al.chemy.org>");
        //pdf.setProperty(PdfSchema.VERSION, "1.4");
        xmp.addRdfDescription(pdf);
        xmp.close();
        singleWriter.setXmpMetadata(os.toByteArray());

        // To avoid transparent colurs being converted from RGB>CMYK>RGB
        // We have to add everything to a transparency group
        PdfTransparencyGroup transGroup = new PdfTransparencyGroup();
        transGroup.put(PdfName.CS, PdfName.DEVICERGB);

        document.open();

        PdfContentByte cb = singleWriter.getDirectContent();
        PdfTemplate tp = cb.createTemplate(bounds.width, bounds.height);

        document.newPage();

        cb.getPdfWriter().setGroup(transGroup);
        // Make sure the color space is Device RGB
        cb.setDefaultColorspace(PdfName.CS, PdfName.DEVICERGB);

        // Draw into the template and add it to the PDF 
        Graphics2D g2pdf = tp.createGraphics(bounds.width, bounds.height);
        Alchemy.canvas.setGuide(false);
        Alchemy.canvas.vectorCanvas.paintComponent(g2pdf);
        Alchemy.canvas.setGuide(true);
        g2pdf.dispose();
        cb.addTemplate(tp, 0, 0);

    } catch (DocumentException ex) {
        System.err.println(ex);
        noError = false;
    } catch (IOException ex) {
        System.err.println(ex);
        noError = false;
    }

    document.close();

    return noError;
}