Example usage for com.itextpdf.layout Document add

List of usage examples for com.itextpdf.layout Document add

Introduction

In this page you can find the example usage for com.itextpdf.layout Document add.

Prototype

@Override
    public Document add(IBlockElement element) 

Source Link

Usage

From source file:controller.ReporteMesController.java

private void generaTablaAutorizaciones(Document doc) throws RemoteException, NotBoundException, IOException {
    Registry reg = LocateRegistry.getRegistry(host, 27019);
    oasisrimbd inter = (oasisrimbd) reg.lookup("OasisSev");
    ArrayList<Autorizado> open = inter.AutorizadoMes((cbmes.getSelectionModel().getSelectedIndex() + 1));
    ArrayList<Invitado> invad = inter.getInvitados();
    List<String> ls = new ArrayList<>();
    for (Autorizado o : open) {
        ls.add(o.getContrato());/*  w  w  w . ja  va  2  s.co  m*/
    }
    invad.removeIf(r -> !(LocalDate.parse(r.getFecha())
            .getMonthValue() == (cbmes.getSelectionModel().getSelectedIndex() + 1)
            && ls.contains(r.getContrato())));
    int inv = 0, invadd = invad.size();
    for (Autorizado r : open) {
        inv += Integer.parseInt(r.getInvitados());
    }
    if (open.size() == 0) {
        inv = 0;
        invadd = 0;
    }
    Table tc = new Table(2);
    Cell c = new Cell();
    c.setFont(PdfFontFactory.createRegisteredFont("times-italic"));
    c.setBorder(Border.NO_BORDER);
    c.add("\n");
    c.add("Numero de titulares");
    c.add("Numero de invitados");
    c.add("Numero de invitados Adicionales");
    c.add("\n");
    tc.addCell(c);
    c = new Cell();
    c.setFont(PdfFontFactory.createRegisteredFont("times-italic"));
    c.setBorder(Border.NO_BORDER);
    c.add("\n");
    c.add(Integer.toString(open.size()));
    c.add(Integer.toString(inv));
    c.add(Integer.toString(invadd));
    c.add("\n");
    tc.addCell(c);
    doc.add(tc);
    List<String> l = Arrays.asList("Usuario", "Autorizado", "Cliente", "Cedula", "Contrato", "Plan", "Fecha",
            "Invitados", "Inv. Adicional");
    tc = generaCabezera(l);
    doc.add(tc);
    for (Autorizado r : open) {
        generaClienteAutorizado(doc, r);
        white *= -1;
    }
}

From source file:controller.ReporteMesController.java

private void generaTablaAcceso(Document doc) throws RemoteException, NotBoundException, IOException {
    Registry reg = LocateRegistry.getRegistry(host, 27019);
    oasisrimbd inter = (oasisrimbd) reg.lookup("OasisSev");
    Table tc;/*from w  ww  .  j  a v  a2  s  . co  m*/
    ArrayList<Login> log = inter.getLogLogins();
    log.removeIf(l -> !(LocalDate.parse(l.getFecha())
            .getMonthValue() == (cbmes.getSelectionModel().getSelectedIndex() + 1)));
    List<String> l = Arrays.asList("Nombre", "Apellido", "Usuario", "Fecha", "Hora");
    tc = generaCabezera(l);
    doc.add(tc);
    for (Login ll : log) {
        generaLogin(doc, ll);
        white *= -1;
    }

}

From source file:controller.ReporteMesController.java

private void generaTablaBusqueda(Document doc) throws RemoteException, NotBoundException, IOException {
    Registry reg = LocateRegistry.getRegistry(host, 27019);
    oasisrimbd inter = (oasisrimbd) reg.lookup("OasisSev");
    Table tc;//from  www.j  a va 2 s  .  c  om
    ArrayList<Busqueda> log = inter.getAllSearch();
    log.removeIf(l -> !(LocalDate.parse(l.getFecha())
            .getMonthValue() == (cbmes.getSelectionModel().getSelectedIndex() + 1)));
    List<String> l = Arrays.asList("Usuario", "Tipo", "Filtro", "Fecha", "Hora");
    tc = generaCabezera(l);
    doc.add(tc);
    for (Busqueda ll : log) {
        generaBusqueda(doc, ll);
        white *= -1;
    }
}

From source file:controller.ReservaController.java

public void exportPDF() throws RemoteException, NotBoundException, FileNotFoundException, IOException {
    Registry reg = LocateRegistry.getRegistry(host, 27019);
    oasiscrud.oasisrimbd inter = (oasiscrud.oasisrimbd) reg.lookup("OasisSev");
    FileChooser file = new FileChooser();
    file.getExtensionFilters().add(new FileChooser.ExtensionFilter("Documento PDF", " *.pdf"));
    File f = file.showSaveDialog(null);
    PdfWriter writer = new PdfWriter(f.getAbsolutePath());
    PdfDocument pdf = new PdfDocument(writer);
    pdf.setDefaultPageSize(PageSize.LETTER);
    Document document = new Document(pdf);
    com.itextpdf.layout.element.Image img = new com.itextpdf.layout.element.Image(
            ImageDataFactory.create(getClass().getResource("/images/pdf-logo.png")));
    img.setHorizontalAlignment(HorizontalAlignment.CENTER);
    document.add(img);
    generaTitulo(document, "Lista de reservaciones");
    document.add(new Paragraph("\n"));
    Table t = generaCabezera(/*from w  w  w. j  a v  a2  s .c o m*/
            Arrays.asList("Titular", "Cedula", "Telefono", "Plan", "Invitados", "Fecha", "Observaciones"));
    document.add(t);
    for (int i = 0; i < table.getItems().size(); i++) {
        generaReservas(document, (Reserva) table.getItems().get(i));
        white *= -1;
    }

    document.close();
}

From source file:controller.ReservaController.java

public void generaReservas(Document doc, Reserva res) throws IOException {
    Table t = new Table(7);
    if (white < 0) {
        t.setBackgroundColor(Color.LIGHT_GRAY);
    }/*from  www. ja va 2s  .co m*/
    t.addCell(generaCeldaNormal(res.getTitular()));
    t.addCell(generaCeldaNormal(res.getCedula()));
    t.addCell(generaCeldaNormal(res.getTelefono()));
    t.addCell(generaCeldaNormal(res.getPlan()));
    t.addCell(generaCeldaNormal(res.getInvitados()));
    t.addCell(generaCeldaNormal(res.getFecha()));
    t.addCell(generaCeldaNormal(res.getObservaciones()));
    doc.add(t);
}

From source file:controller.VisitasController.java

public void generaPDF(ActionEvent evt)
        throws FileNotFoundException, MalformedURLException, IOException, RemoteException, NotBoundException {

    Registry reg = LocateRegistry.getRegistry(host, 27019);
    oasiscrud.oasisrimbd inter = (oasiscrud.oasisrimbd) reg.lookup("OasisSev");

    FileChooser file = new FileChooser();
    file.getExtensionFilters().add(new FileChooser.ExtensionFilter("Documento PDF", " *.PDF"));
    File f = file.showSaveDialog(null);
    PdfWriter writer = new PdfWriter(f.getAbsolutePath());

    PdfDocument pdf = new PdfDocument(writer);
    pdf.setDefaultPageSize(PageSize.LETTER.rotate());

    Document document = new Document(pdf);

    com.itextpdf.layout.element.Cell c;/*from   w  w  w.  j a  v  a  2 s .  c  o m*/
    Table tc;
    Paragraph p = new Paragraph();
    Image img = new Image(ImageDataFactory.create(getClass().getResource("/images/pdf-logo.png")));
    img.setHorizontalAlignment(com.itextpdf.layout.property.HorizontalAlignment.CENTER);
    document.add(img);

    document.add(new Paragraph("\n"));

    generaTitulo(document, "Detalles de asistencias General");
    generaTablaAsistencia(document);
    pdf.addNewPage();
    document.add(new AreaBreak());

    document.close();
    System.out.println(f.getAbsolutePath());
}

From source file:controller.VisitasController.java

private void generaTablaAsistencia(Document doc) throws IOException, RemoteException, NotBoundException {
    Registry reg = LocateRegistry.getRegistry(host, 27019);
    oasisrimbd inter = (oasisrimbd) reg.lookup("OasisSev");
    ArrayList<Asistencia> asist = new ArrayList<>(table.getItems());
    ArrayList<Invitado> invad = inter.getInvitados();
    List<String> ls = new ArrayList<>();
    for (Asistencia o : asist) {
        ls.add(o.getContrato());/*from w ww .  j a  v  a2s  .c o m*/
    }
    invad.removeIf(r -> !(r.getFecha().equals(date.getValue().format(DateTimeFormatter.ISO_LOCAL_DATE))
            && ls.contains(r.getContrato())));
    int inv = 0, invadd = invad.size();
    for (Asistencia a : asist) {
        inv += Integer.parseInt(a.getInvitados());
    }

    Table tc = new Table(2);
    com.itextpdf.layout.element.Cell c = new com.itextpdf.layout.element.Cell();
    c.setFont(PdfFontFactory.createRegisteredFont("times-italic"));
    c.setBorder(Border.NO_BORDER);
    c.add("\n");
    c.add("Numero de titulares");
    c.add("Numero de invitados");
    c.add("Numero de invitados Adicionales");
    c.add("\n");
    tc.addCell(c);
    c = new com.itextpdf.layout.element.Cell();
    c.setFont(PdfFontFactory.createRegisteredFont("times-italic"));
    c.setBorder(Border.NO_BORDER);
    c.add("\n");
    c.add(Integer.toString(asist.size()));
    c.add(Integer.toString(inv));
    c.add(Integer.toString(invadd));
    c.add("\n");
    tc.addCell(c);
    doc.add(tc);
    ArrayList<String> l = new ArrayList<>(
            Arrays.asList("Cedula", "Cliente", "Contrato", "Plan", "Fecha", "Invitados", "Inv Adicionales"));
    tc = generaCabezera(l);
    doc.add(tc);
    for (Asistencia a : asist) {
        generaClienteAsistencia(doc, a);
        white *= -1;
    }

}

From source file:controller.VisitasController.java

private void generaTitulo(Document document, String text) throws IOException {
    Table t = new Table(1);
    com.itextpdf.layout.element.Cell c = new com.itextpdf.layout.element.Cell();
    c.setTextAlignment(TextAlignment.CENTER);
    c.setFont(PdfFontFactory.createRegisteredFont("times-italic"));
    c.setFontSize(16);// ww  w  .j  a va  2 s . c  o m
    c.setFontColor(Color.GRAY);
    c.add("\n");
    c.add(text);
    c.setBorder(Border.NO_BORDER);
    t.addCell(c);
    document.add(t);
}

From source file:machinetoolstore.core.util.PdfGenerator.java

public static boolean getGeneratedPdfByArtifact(ThreeRollMill artifact, String fileName) throws Exception {
    PdfWriter writer = new PdfWriter(GENERATED_FILES_PATH + fileName);
    PdfDocument pdfDocument = new PdfDocument(writer);
    Document document = new Document(pdfDocument, PageSize.A4);

    document.setMargins(15, 15, 15, 40);
    PdfFont mainFont = PdfFontFactory.createFont(FONTS_PATH + "calibril.ttf", "cp1251", false);

    //Header/*from w  w w  . ja v a 2  s.  com*/
    Paragraph headerParagraph = new Paragraph(artifact.getBrand() + " " + artifact.getModel());
    headerParagraph.setItalic();
    headerParagraph.setTextAlignment(TextAlignment.CENTER);
    headerParagraph.setFont(mainFont);
    headerParagraph.setFontSize(20);
    document.add(headerParagraph);

    //Image block witch characteristic
    Table table = new Table(3);
    table.setWidthPercent(100);

    //Image cell
    Cell imageCell = new Cell();
    imageCell.setBorder(Border.NO_BORDER);
    Image machineImage = new Image(ImageDataFactory.create(IMAGE_PATH + artifact.getMainPhoto()));
    machineImage.setWidth(100);
    machineImage.setHeight(100);
    imageCell.add(machineImage);

    //Main characteristic cell
    Cell mainCharacteristicCell = new Cell();
    List mainCharacteristicList = new List().setSymbolIndent(5).setListSymbol("\uFFFF").setFont(mainFont)
            .setFontSize(12);
    mainCharacteristicList.add("ID:").add(":").add(" ?:")
            .add("?:").add("??:").add(", $:");
    mainCharacteristicCell.add(mainCharacteristicList);

    Cell valuesCell = new Cell();
    List valuesList = new List().setSymbolIndent(5).setListSymbol("\uFFFF").setFont(mainFont).setFontSize(12);
    valuesList.add(artifact.getId().toString()).add(artifact.getManufacturer())
            .add(artifact.getYearOfIssue().toString()).add(artifact.getLocation())
            .add(artifact.getMachineState()).add(artifact.getMachinePrice().toString());
    valuesCell.add(valuesList);

    table.addCell(imageCell);
    table.addCell(mainCharacteristicCell);
    table.addCell(valuesCell);

    //Paragraph
    Paragraph contentParagraph = new Paragraph("? ?");
    contentParagraph.setItalic();
    contentParagraph.setTextAlignment(TextAlignment.CENTER);
    contentParagraph.setFont(mainFont);
    contentParagraph.setFontSize(14);
    contentParagraph.setFixedPosition(1, 635, 600);
    document.add(contentParagraph);

    //Main table
    Table mainTable = new Table(2);
    mainTable.setFont(mainFont);
    mainTable.setFontSize(10);
    mainTable.setMarginTop(35);
    mainTable.addCell(" ?").addCell(artifact.getType());
    mainTable.addCell(" , ")
            .addCell(artifact.getMaterialThickness().toString());
    mainTable.addCell(" , ").addCell(artifact.getMaterialWidth().toString());
    mainTable.addCell("? , /").addCell(artifact.getBendingSpeed().toString());
    mainTable.addCell("Min   max ?, ")
            .addCell(artifact.getMinDiameterMaxBend().toString());
    mainTable.addCell("  , ")
            .addCell(artifact.getTopRollDiameter().toString());
    mainTable.addCell(" ? , ")
            .addCell(artifact.getMiddleRollDiameter().toString());
    mainTable.addCell("???   ? , ")
            .addCell(artifact.getDistanceOfBottomTwoRolls().toString());
    mainTable.addCell(
            "?  ? ?  ?, ")
            .addCell(artifact.getMaterialProofStress().toString());
    mainTable.addCell("?  ?, ")
            .addCell(artifact.getMainEnginePower().toString());
    mainTable.addCell(" , ").addCell(artifact.getMachineDimensions());
    mainTable.addCell("? ?, ").addCell(artifact.getMachineWeight().toString());
    mainTable.addCell("?").addCell(artifact.getDescription());

    document.add(table);
    document.add(mainTable);
    document.close();

    return true;
}

From source file:model.PrintPDF.java

public void inThongKeCanBo(ArrayList<CanBo> listCanBo, String pathName, String nam, int gt, String tongNhanVien,
        String soNVVH) {/*w  w w  .j  a va 2  s  .  c  o m*/
    PdfWriter pdfWriter = null;
    String gioiTinh = "";
    if (gt == 1) {
        gioiTinh = "n";
    } else {
        gioiTinh = "nam";
    }

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k cn b " + gioiTinh + " nm " + nam + "\n\n").setFont(hfont)
                .setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 2, 4, 3, 4 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("S in thoi").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));

        //  ni dung ca bng thng k
        for (int i = 0; i < listCanBo.size(); i++) {
            table.addCell(new Paragraph((i + 1) + "").setFont(hfont).setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(listCanBo.get(i).getMaCB()).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(listCanBo.get(i).getHoTen()).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(dateFormat.format(listCanBo.get(i).getNgaySinh())).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(listCanBo.get(i).getSDT()).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
        }
        document.add(table);
        document.add(new Paragraph("\n\n Tng s nhn vin            :  " + tongNhanVien).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));
        document.add(new Paragraph(" Tng s nhn vin sp v? hu :  " + tongNhanVien).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));

        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}