Example usage for com.itextpdf.text Document addLanguage

List of usage examples for com.itextpdf.text Document addLanguage

Introduction

In this page you can find the example usage for com.itextpdf.text Document addLanguage.

Prototype

public boolean addLanguage(String language) 

Source Link

Document

Adds a language to th document.

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;/*from w w w .j  a v  a  2  s  . c  o  m*/
    try {
        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:pdf.PdfBuilder.java

/**
 * Creates an accessible PDF with images and text.
 * @param dest  the path to the resulting PDF
 * @throws IOException//  www  .j  a  v  a2 s  .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:PROCESOS.ImprimirPDF.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/pdf");
    String precio_unitario = request.getParameter("precio");

    String id_vale = request.getParameter("codigo");

    //  if(request.getParameter("codigo")!=null){
    OutputStream salida = response.getOutputStream();
    try {/* w w w  .  j  a  v a2s  . c  o m*/

        try {

            DTO.ClaseTransaccion clase = new ClaseTransaccion();
            clase = consulta.Transaccion();
            Document documento = new Document(PageSize.A4, 36, 36, 45, 20);
            PdfWriter pw = PdfWriter.getInstance(documento, salida);
            documento.open();
            Paragraph parrafo1 = new Paragraph();
            Font font_titulo = new Font(Font.FontFamily.HELVETICA, 16, Font.UNDERLINE, BaseColor.BLACK);
            parrafo1.add(new Phrase("TecnoBencina, COMPROBANTE", font_titulo));
            parrafo1.setAlignment(Element.ALIGN_CENTER);
            parrafo1.add(new Phrase(Chunk.NEWLINE));
            parrafo1.add(new Phrase(Chunk.NEWLINE));
            documento.add(parrafo1);

            Paragraph parrafo2 = new Paragraph();
            Font font_titulo_p2 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK);

            if (id_vale.length() > 0) {
                parrafo2.add(new Phrase("Comprobante de transaccion : codigo del vale : " + id_vale,
                        font_titulo_p2));
            } else {
                parrafo2.add(new Phrase("Comprobante de transaccion ", font_titulo_p2));
            }

            parrafo2.setAlignment(Element.ALIGN_JUSTIFIED);
            parrafo2.add(new Phrase(Chunk.NEWLINE));
            parrafo2.add(new Phrase(Chunk.NEWLINE));
            parrafo2.add(new Phrase(Chunk.NEWLINE));
            documento.add(parrafo2);

            PdfPTable tabla = new PdfPTable(9);
            PdfPCell celda1 = new PdfPCell(new Paragraph("ID transaccion ",
                    FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda2 = new PdfPCell(
                    new Paragraph("Estado ", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda3 = new PdfPCell(new Paragraph("ID de surtidor",
                    FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda4 = new PdfPCell(
                    new Paragraph("Litros", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda5 = new PdfPCell(
                    new Paragraph("Monto", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda6 = new PdfPCell(
                    new Paragraph("Fecha", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda7 = new PdfPCell(
                    new Paragraph("ID pago", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda8 = new PdfPCell(new Paragraph("Precio unitario",
                    FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));

            tabla.addCell(celda1);
            tabla.addCell(celda2);
            tabla.addCell(celda3);
            tabla.addCell(celda4);
            tabla.addCell(celda5);
            tabla.addCell(celda6);
            tabla.addCell(celda7);
            tabla.addCell(celda8);

            tabla.addCell(String.valueOf(clase.getId_transaccion()));
            tabla.addCell(clase.getEstado());
            tabla.addCell(String.valueOf(clase.getId_transaccion()));
            tabla.addCell(String.valueOf(clase.getLitros()));
            tabla.addCell(String.valueOf(clase.getMonto()));
            tabla.addCell(String.valueOf(clase.getFecha()));
            tabla.addCell(String.valueOf(clase.getId_pago()));
            tabla.addCell(precio_unitario);

            documento.add(tabla);
            documento.addAuthor("TecnoBencina");
            documento.addTitle("Comprobante");
            documento.addLanguage("Espaol");
            documento.add(new Paragraph(new Phrase(Chunk.NEWLINE)));
            documento.add(new Paragraph(new Phrase(Chunk.NEWLINE)));

            documento.add(new Paragraph(new Phrase(Chunk.NEWLINE)));
            documento.add(new Paragraph(new Phrase(Chunk.NEWLINE)));
            documento.add(new Paragraph("texto....", font_titulo_p2));
            documento.close();
        } catch (Exception s) {
            s.getMessage();
        }

    } catch (Exception s) {
        System.out.println("" + s.getMessage());
    } finally {
        salida.close();
    }
    // }
}