Example usage for com.itextpdf.text.pdf PdfWriter createXmpMetadata

List of usage examples for com.itextpdf.text.pdf PdfWriter createXmpMetadata

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfWriter createXmpMetadata.

Prototype

public void createXmpMetadata() 

Source Link

Document

Use this method to creates XMP Metadata based on the metadata in the PdfDocument.

Usage

From source file:com.unicauca.coordinacionpis.managedbean.RegistroFormatoAController.java

public void agregarMetadatos() {
    // create document and writer
    Document document = new Document(PageSize.A4);
    PdfWriter writer;
    try {/*from  w w  w.  jav  a2 s.  co  m*/
        writer = PdfWriter.getInstance(document, new FileOutputStream("D:\\aguaabril2016.pdf"));
        // add meta-data to pdf
        document.addAuthor("Memorynotfound");
        document.addCreationDate();
        document.addCreator("Memorynotfound.com");
        document.addTitle("Add meta data to PDF");
        document.addSubject("how to add meta data to pdf using itext");
        document.addKeywords(metadatosAnteproyectos.getTitulo() + "," + metadatosAnteproyectos.getProfesor());
        document.addLanguage(Locale.ENGLISH.getLanguage());
        document.addHeader("type", "tutorial, example");

        // add xmp meta data
        writer.createXmpMetadata();

        document.open();
        document.add(new Paragraph("Add meta-data to PDF using iText"));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RegistroOfertaAcademicaController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(RegistroOfertaAcademicaController.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:engine.Pdf.java

@Deprecated
public static void start(Vector<HoughLine> vectors, int width, int height) {
    try {//from ww  w .j a v a  2 s . c o  m
        Rectangle size = new Rectangle(width, height);
        Document document = new Document(size);

        //            document.setPageSize(size);
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(new File("source", "output.pdf")));
        writer.createXmpMetadata();
        document.open();
        addMetaData(document);
        //            addTitlePage(document);
        //            addContent(document);
        drawLines(vectors, writer);
        document.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:pdf.PdfBuilder.java

/**
 * Creates an accessible PDF with images and text.
 * @param dest  the path to the resulting PDF
 * @throws IOException/*from   w  w  w.j a v a 2s.  co  m*/
 * @throws DocumentException
 */
public String createPdf(Invoice invoice) throws IOException, DocumentException {
    DEST = "C://temp/";
    SimpleDateFormat sdf = new SimpleDateFormat("MM");
    DEST += invoice.getCar().getId() + "month"
            + sdf.format(invoice.getSeriesOfLocationsOnRoad().get(0).getLocations().get(0).getDate()) + ".pdf";

    File file = new File(DEST);
    file.getParentFile().mkdirs();

    Document document = new Document(PageSize.A4.rotate());
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));
    writer.setPdfVersion(PdfWriter.VERSION_1_7);
    //TAGGED PDF
    //Make document tagged
    writer.setTagged();
    //===============
    //PDF/UA
    //Set document metadata
    writer.setViewerPreferences(PdfWriter.DisplayDocTitle);
    document.addLanguage("en-US");
    document.addTitle("Factuur voor auto " + invoice.getCar().getLicensePlate());
    writer.createXmpMetadata();
    //=====================
    document.open();

    Font font = FontFactory.getFont(FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 20);

    double amountPaidForDistance = invoice.getTotalAmount();
    double amountPaidForCordons = 0;

    for (Cordon c : invoice.getCordonOccurrences()) {
        amountPaidForDistance -= c.getAmount();
        amountPaidForCordons += c.getAmount();
    }

    Paragraph p = new Paragraph("\n", font);
    p.add(new Chunk("Aantal gereden kilometers:"));
    p.add(new Chunk("\n"));
    p.add(new Chunk(String.valueOf(invoice.getTotalDistance()) + " kilometer"));
    p.add(new Chunk("\n"));
    p.add(new Chunk("Met een gemiddeld tarief van " + (amountPaidForDistance / invoice.getTotalDistance() * 100)
            + " eurocent per kilometer"));
    p.add(new Chunk("\n"));
    p.add(new Chunk("Bedrag dat betaald dient te worden over de kilometers: "));
    p.add(new Chunk("\n"));
    p.add(new Chunk(amountPaidForDistance + " euro"));
    document.add(p);

    p = new Paragraph("\n\n", font);
    p.add(new Chunk(invoice.cordonOccurrencesString()));
    p.add(new Chunk("\n"));
    p.add(new Chunk("Bedrag dat betaald dient te worden over de cordons: "));
    p.add(new Chunk("\n"));
    p.add(new Chunk(amountPaidForCordons + " euro"));
    document.add(p);

    p = new Paragraph("\n\n", font);
    p.add(new Chunk("Totaal bedrag dat betaald dient te worden: "));
    p.add(new Chunk("\n"));
    p.add(new Chunk(String.valueOf(invoice.getTotalAmount()) + " euro"));
    document.add(p);
    document.close();

    return DEST;
}

From source file:pdfcreator.PDFCreator.java

License:Open Source License

@SuppressWarnings("static-access")
protected void createPdf(String filename, String[] images) throws Exception {
    Document doc = new Document();
    PdfWriter writer;

    if (pdfxConformance.equals("PDFA1A")) {
        writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_1A);
    } else if (pdfxConformance.equals("PDFA1B")) {
        writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_1B);
    } else if (pdfxConformance.equals("PDFA2A")) {
        writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_2A);
    } else if (pdfxConformance.equals("PDFA2B")) {
        writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_2B);
    } else if (pdfxConformance.equals("PDFA3A")) {
        writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_3A);
    } else if (pdfxConformance.equals("PDFA3B")) {
        writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_3B);
    } else {/*  ww w  .j a v a 2  s.  com*/
        writer = PdfWriter.getInstance(doc, new FileOutputStream(filename));
    }

    if (pdfVersion.equals("1.4")) {
        writer.setPdfVersion(PdfWriter.VERSION_1_4);
    } else if (pdfVersion.equals("1.5")) {
        writer.setPdfVersion(PdfWriter.VERSION_1_5);
    } else if (pdfVersion.equals("1.6")) {
        writer.setPdfVersion(PdfWriter.VERSION_1_6);
    } else if (pdfVersion.equals("1.7")) {
        writer.setPdfVersion(PdfWriter.VERSION_1_7);
    } else {
        writer.setPdfVersion(PdfWriter.VERSION_1_4);
    }

    verbose(filename + ": open");

    doc.addCreationDate();
    doc.addCreator(creator);

    if (title != null) {
        doc.addTitle(title);
    }

    for (int i = 0; i < images.length; i++) {
        verbose(" +" + images[i]);

        Image img = Image.getInstance(images[i]);

        doc.setPageSize(new Rectangle(img.getWidth(), img.getHeight()));
        doc.setMargins(0, 0, 0, 0);

        if (doc.isOpen()) {
            doc.newPage();
        } else {
            doc.open();
        }

        doc.add(img);

        doc.newPage();
    }

    ICC_Profile icc = getImageColorProfile(images[0]);

    if (icc == null) {
        System.err.println("warning: no color profile available in " + images[0] + " using " + profileName);
        icc = getDefaultColorProfile();
    }

    writer.setOutputIntents("Custom", "", null, null, icc);

    writer.createXmpMetadata();

    doc.close();

    verbose(filename + ": close");
}