Example usage for com.itextpdf.text Paragraph setAlignment

List of usage examples for com.itextpdf.text Paragraph setAlignment

Introduction

In this page you can find the example usage for com.itextpdf.text Paragraph setAlignment.

Prototype

public void setAlignment(int alignment) 

Source Link

Document

Sets the alignment of this paragraph.

Usage

From source file:edu.uv.controller.ExamenPreguntaController.java

protected void encabezado(Document pdfExamen, ExamenesGenerados examen) {

    try {//w w  w.java2 s  . c o  m
        Paragraph titulo = new Paragraph("UNIVERSIDAD VERACRUZANA", catFont);
        titulo.setAlignment(Paragraph.ALIGN_CENTER);
        pdfExamen.add(titulo);
        titulo = new Paragraph(examen.getPeriodo(), smallBold);
        titulo.setAlignment(Paragraph.ALIGN_CENTER);
        pdfExamen.add(titulo);
        titulo = new Paragraph("Examen " + examen.getTipoExamen(), smallBold);
        titulo.setAlignment(Paragraph.ALIGN_CENTER);
        pdfExamen.add(titulo);
        titulo = new Paragraph(examen.getExperieciaEducativa().getNombreEe(), smallBold);
        titulo.setAlignment(Paragraph.ALIGN_CENTER);
        pdfExamen.add(titulo);
        pdfExamen.add(new Paragraph("Porcentajes : Teoria " + examen.getPorcTeoria() + "%  Practica "
                + examen.getPorcPractica() + " %", smallBold));
        pdfExamen.add(new Paragraph(
                "Profesor: ________________________________________________________________________ ",
                smallBold));
        pdfExamen.add(new Paragraph(
                "Alumno: __________________________________________________________________________ ",
                smallBold));
        pdfExamen.add(new Paragraph(" ", smallBold));
    } catch (DocumentException ex) {

    }
}

From source file:emailworkshop.EmailWorkshop.java

public static void gerarPDF(String nome, int numCert) {
    Calendar data = Calendar.getInstance();

    // criao do objeto documento
    Document document = new Document() {
    };/*from  w w w.j a v  a  2s.  c om*/
    document.setPageSize(new Rectangle(800, 500));
    try {

        PdfWriter.getInstance(document, new FileOutputStream("Certificado.pdf"));
        document.open();

        // adicionando um pargrafo ao documento
        Image img = Image.getInstance("logo.png");

        img.scaleAbsoluteWidth(620);
        img.scaleAbsoluteHeight(130);
        Paragraph texto1 = new Paragraph("\n Conferimos o presente Certificado a " + nome + " por ter "
                + "participado do II Workshop de Inovao, com durao de 4 horas. Onde foram apresentadas as palestras: ");
        Paragraph texto2 = new Paragraph(
                "Economia compartilha & Inovao Disruptiva - Arthur Schuler da Igreja.\n"
                        + "Empreendedorismo: Um case de sucesso - Cludio Kopp.");
        Paragraph texto3 = new Paragraph(
                "\n\n\n\n\nRegistrado na UFPR Setor Palotina Livro 4 certificado Nr " + numCert + ".");

        Paragraph localData = new Paragraph("\nPalotina, " + new SimpleDateFormat("dd").format(data.getTime())
                + " de " + new SimpleDateFormat("MMMM").format(data.getTime()) + " de "
                + new SimpleDateFormat("yyyy").format(data.getTime()) + ".\n\n");

        texto1.setAlignment("center");
        texto2.setAlignment("center");
        texto3.setAlignment("right");
        localData.setAlignment("center");

        Image assinatura = Image.getInstance("assinatura.png");
        assinatura.scaleAbsoluteHeight(75);
        assinatura.scaleAbsoluteWidth(250);
        assinatura.setAbsolutePosition(275, 110);

        document.add(img);
        document.add(texto1);
        document.add(texto2);
        document.add(localData);

        document.add(assinatura);
        document.add(texto3);

        document.close();
    } catch (DocumentException | IOException de) {
        System.err.println(de.getMessage());
    }

}

From source file:es.baudlord.pcpartpicker.controller.BuildViewController.java

License:Open Source License

@FXML
public void onBillAction(ActionEvent event) {
    if (build.isComplete()) {
        try {/*  w  w w.j  a v  a  2 s  .  c  o  m*/
            FileChooser chooser = new FileChooser();
            chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF", "*.pdf"));
            File file = chooser.showSaveDialog(((Node) event.getSource()).getScene().getWindow());
            if (file == null)
                return;
            Document document = new Document();
            PdfWriter.getInstance(document, new FileOutputStream(file));
            document.open();
            // Begin header generation
            PdfPTable table = new PdfPTable(2);
            table.setWidths(new int[] { 3, 7 });
            com.itextpdf.text.Image image = com.itextpdf.text.Image
                    .getInstance(App.class.getResource("img/logo.png"));
            image.scaleToFit(100f, 100f);
            PdfPCell cell = new PdfPCell(image);
            cell.setBorder(0);
            PdfPCell cell2 = new PdfPCell(
                    new Paragraph("Hipster PC Store", new Font(Font.FontFamily.HELVETICA, 30)));
            cell2.setBorder(0);
            cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
            table.addCell(cell2);
            document.add(table);
            // End header generation
            document.add(build.createPdfPTable(new Font(Font.FontFamily.COURIER, 7)));
            // Begin generate date warning
            Calendar cal = Calendar.getInstance();
            Instant now = cal.toInstant();
            cal.add(Calendar.DAY_OF_MONTH, 7);
            Instant end = cal.toInstant();
            DateTimeFormatter localFormat = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
                    .withZone(ZoneId.systemDefault());
            Paragraph p1 = new Paragraph(GENERAL_BUNDLE.getString("bill.date.warning"),
                    new Font(Font.FontFamily.COURIER, 10, Font.BOLD));
            Paragraph p2 = new Paragraph(
                    GENERAL_BUNDLE.getString("bill.date.emitted") + " " + localFormat.format(now) + "\n"
                            + GENERAL_BUNDLE.getString("bill.date.valid") + " " + localFormat.format(end),
                    new Font(Font.FontFamily.COURIER, 10));
            p1.setAlignment(Element.ALIGN_CENTER);
            p2.setAlignment(Element.ALIGN_CENTER);
            document.add(p1);
            document.add(p2);
            // End generate date warning
            document.close();
            Alert dialog = new Alert(Alert.AlertType.CONFIRMATION);
            dialog.setTitle(GENERAL_BUNDLE.getString("bill.generated")); // TODO: translate
            dialog.setHeaderText(GENERAL_BUNDLE.getString("bill.validity"));
            dialog.getButtonTypes().setAll(ButtonType.CLOSE,
                    new ButtonType(GENERAL_BUNDLE.getString("button.Print"), ButtonBar.ButtonData.FINISH),
                    new ButtonType(GENERAL_BUNDLE.getString("button.ShowPDF"), ButtonBar.ButtonData.OK_DONE));
            dialog.showAndWait();
            if (dialog.getResult() != null) {
                ButtonBar.ButtonData result = dialog.getResult().getButtonData();
                if (result.equals(ButtonBar.ButtonData.FINISH)) {
                    Desktop.getDesktop().print(file);
                } else if (result.equals(ButtonBar.ButtonData.OK_DONE)) {
                    Desktop.getDesktop().open(file);
                }
            }
        } catch (DocumentException | IOException e) {
            e.printStackTrace();
        }
    } else {
        Alert dialog = new Alert(Alert.AlertType.WARNING);
        dialog.getButtonTypes().setAll(
                new ButtonType(GENERAL_BUNDLE.getString("button.tryAgain"), ButtonBar.ButtonData.OK_DONE),
                ButtonType.CANCEL);
        dialog.setTitle(GENERAL_BUNDLE.getString("dialog.build.incomplete"));
        List<Product.Category> missing = build.getMissingMandatoryParts();
        dialog.setHeaderText(GENERAL_BUNDLE.getString("dialog.build.needed"));
        final HBox content = new HBox(10);
        missing.forEach(category -> {
            Button button = new Button(App.PART_NAMES_BUNDLE.getString(category.toString()));
            button.setGraphic(Category.getGraphic(category, 30));
            button.setContentDisplay(ContentDisplay.TOP);
            button.setId(category.toString());
            button.setOnAction(actionEvent -> {
                try {
                    Part part = pickNewPart(category);
                    if (part != null) {
                        saved.set(false);
                        build.add(part);
                        displayBuild();
                        if (Category.isStorage(category)) {
                            content.getChildren()
                                    .removeIf(node -> node.getId().equals(Product.Category.HDD_SSD.toString())
                                            || node.getId().equals(Product.Category.HDD.toString()));
                            content.autosize();
                        } else {
                            content.getChildren().remove(button);
                        }
                        dialog.getDialogPane().getScene().getWindow().sizeToScene();
                        if (content.getChildren().isEmpty()) {
                            buttonBill.fire();
                            dialog.close();
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
            content.getChildren().add(button);
        });
        dialog.getDialogPane().setContent(content);
        dialog.showAndWait();
        ButtonType result = dialog.getResult();
        if (result != null && result.getButtonData().equals(ButtonBar.ButtonData.OK_DONE)) {
            dialog.hide();
            onBillAction(event);
        }
    }
}

From source file:es.clinica.veterinaria.albaranes.AlbaranPdf.java

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from   w  w w .java2 s.c om*/
    // Lets write a big header
    String fecha = new SimpleDateFormat("dd / MM / yyyy").format(venta.getFecha());
    preface.add(new Paragraph("ALBAR?N N " + venta.getId()
            + "                                                            " + fecha, catFont));

    addEmptyLine(preface, 2);
    document.add(preface);
    // Will create: Report generated by: _name, _date
    //preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    //    smallBold));
    //addEmptyLine(preface, 3);
    //preface.add(new Paragraph("This document describes something which is very important ", smallBold));
    preface = new Paragraph("SERVICIOS MDICOS-VETERINARIOS");
    preface.setAlignment(Element.ALIGN_CENTER);
    addEmptyLine(preface, 2);
    document.add(preface);

    preface = new Paragraph("Cliente: " + venta.getCliente().getFullname() + "\nTelfono: "
            + venta.getCliente().getTelefono());
    preface.setAlignment(Element.ALIGN_LEFT);
    addEmptyLine(preface, 2);
    document.add(preface);
    //preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
    //    redFont));

    //document.add(preface);
    // Start a new page
    // document.newPage();
}

From source file:es.clinica.veterinaria.facturas.FacturaPdf.java

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//from ww w  . j  a v  a  2s .co m
    // Lets write a big header
    String fecha = new SimpleDateFormat("dd / MM / yyyy").format(factura.getFecha());

    //        Paragraph titulo = new Paragraph("FACTURA N " + factura.getNumero() +
    //                                  "\nFecha: " + fecha, catFont);
    //        titulo.setAlignment(Element.ALIGN_RIGHT);

    //        preface.add(titulo);
    addEmptyLine(preface, 2);

    document.add(preface);

    //        preface = new Paragraph("CENTRO VETERINARIO \"El Rey de la Casa\"");
    preface.setAlignment(Element.ALIGN_RIGHT);
    addEmptyLine(preface, 2);
    document.add(preface);

    //        preface = new Paragraph("Cliente: " + factura.getCliente().getFullname() +
    //                                "\nNIF/CIF: " + factura.getCliente().getNif() +
    //                                "\n" + factura.getCliente().getDireccion() +
    //                                "\n" + factura.getCliente().getCiudad().getPoblacion() +
    //                                " (" + factura.getCliente().getProvincia().getProvincia() + ")" +
    //                                "\nTelfono: " + factura.getCliente().getTelefono(), smallBold);
    //        preface.setAlignment(Element.ALIGN_LEFT);
    addEmptyLine(preface, 2);
    document.add(preface);
    //preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
    //    redFont));

    //document.add(preface);
    // Start a new page
    // document.newPage();
}

From source file:es.sm2.openppm.front.utils.DocumentUtils.java

License:Open Source License

/**
 * Create PDF for Control Change/*  w w  w .j a  va 2s . c o  m*/
 * @param idioma
 * @param project
 * @param change
 * @param preparedBy
 * @return
 * @throws DocumentException
 * @throws LogicException
 */
public static byte[] toPdf(ResourceBundle idioma, Project project, Changecontrol change, Employee preparedBy,
        final Image headerImg, final Image footerImg) throws DocumentException, LogicException {

    if (change == null) {
        throw new DocumentException("No change control found.");
    }

    if (preparedBy == null || preparedBy.getContact() == null) {
        throw new UserSendingException();
    }

    Document document = new Document(PageSize.A4);
    document.setMargins(70F, 70F, 38F, 38F); // Total Height: 842pt, Total Width: 595pt
    byte[] file = null;

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    @SuppressWarnings("unused")
    PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);

    document.open();

    Font fontHeader = new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD);
    Font fontCell = new Font(FontFamily.TIMES_ROMAN, 9);
    Font tituloFont = new Font(FontFamily.TIMES_ROMAN, 16, Font.BOLD);

    document.add(new Paragraph(" ", tituloFont));
    document.add(new Paragraph(" ", tituloFont));
    document.add(new Paragraph(" ", fontHeader));
    Paragraph title = new Paragraph(idioma.getString("change_request").toUpperCase(), tituloFont);
    title.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(title);

    // Header Table
    // Project info
    PdfPTable tableHeader = new PdfPTable(3);
    tableHeader.setWidthPercentage(100);
    tableHeader.setSpacingBefore(10);
    tableHeader.setSpacingAfter(15);

    int[] colWidth = new int[3];
    colWidth[0] = 40;
    colWidth[1] = 30;
    colWidth[2] = 30;
    tableHeader.setWidths(colWidth);

    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.project_name"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.prepared_by"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(prepareHeaderCell(idioma.getString("change_request.date"), fontHeader, 1F, 1F, 0F, 1F));

    tableHeader.addCell(prepareCell(project.getProjectName() + " / " + project.getAccountingCode(), fontCell,
            0F, 0F, 0F, 1F));
    tableHeader.addCell(prepareCell(preparedBy.getContact().getFullName(), fontCell, 0F, 0F, 0F, 1F));
    tableHeader.addCell(prepareCell(DateUtil.format(idioma, new Date()), fontCell, 0F, 1F, 0F, 1F));

    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.customer"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.contact_name"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.customer_type"), fontHeader, 1F, 1F, 0F, 1F));

    tableHeader.addCell(prepareCell(project.getCustomer() != null ? project.getCustomer().getName() : "",
            fontCell, 0F, 0F, 0F, 1F));
    tableHeader.addCell(prepareCell((project.getCustomer() != null ? project.getCustomer().getName() : "-"),
            fontCell, 0F, 0F, 0F, 1F));

    Customertype cusType = (project.getCustomer() != null ? project.getCustomer().getCustomertype() : null);
    tableHeader.addCell(prepareCell(cusType == null ? "" : cusType.getName(), fontCell, 0F, 1F, 0F, 1F));

    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.business_manager"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.project_manager"), fontHeader, 1F, 0F, 0F, 1F));
    tableHeader.addCell(
            prepareHeaderCell(idioma.getString("change_request.originator"), fontHeader, 1F, 1F, 0F, 1F));

    Employee bm = project.getEmployeeByFunctionalManager();
    Employee pm = project.getEmployeeByProjectManager();

    tableHeader.addCell(prepareCell(bm == null ? "" : bm.getContact().getFullName(), fontCell, 0F, 0F, 1F, 1F));
    tableHeader.addCell(prepareCell(pm == null ? "" : pm.getContact().getFullName(), fontCell, 0F, 0F, 1F, 1F));
    tableHeader.addCell(prepareCell(change.getOriginator(), fontCell, 0F, 1F, 1F, 1F));

    document.add(tableHeader);

    // Change Information
    document.add(new Paragraph(idioma.getString("change_information")));

    PdfPTable tableInfo = new PdfPTable(1);
    tableInfo.setWidthPercentage(100);
    tableInfo.setSpacingBefore(10);
    tableInfo.setSpacingAfter(15);

    tableInfo.addCell(prepareHeaderCell(idioma.getString("change.change_type"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(change.getChangetype().getDescription(), fontCell, 0F, 1F, 0F, 1F));

    String priorityDesc = "";
    if (change.getPriority().equals('H'))
        priorityDesc = idioma.getString("change.priority.high");
    if (change.getPriority().equals('N'))
        priorityDesc = idioma.getString("change.priority.normal");
    if (change.getPriority().equals('L'))
        priorityDesc = idioma.getString("change.priority.low");

    tableInfo.addCell(prepareHeaderCell(idioma.getString("change.priority"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(priorityDesc, fontCell, 0F, 1F, 0F, 1F));

    tableInfo.addCell(prepareHeaderCell(idioma.getString("change.desc"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(change.getDescription(), fontCell, 0F, 1F, 0F, 1F));

    tableInfo.addCell(
            prepareHeaderCell(idioma.getString("change.recommended_solution"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(change.getRecommendedSolution(), fontCell, 0F, 1F, 1F, 1F));

    PdfPTable tableSubInfo = new PdfPTable(3);
    tableSubInfo.setWidthPercentage(100);

    //TODO MIGRACION
    tableSubInfo.addCell(prepareSubCell(idioma.getString("change.wbs_node"), fontHeader));
    tableSubInfo.addCell(prepareSubCell(idioma.getString("change.estimated_effort"), fontHeader));
    tableSubInfo.addCell(prepareSubCell(idioma.getString("change.estimated_cost"), fontHeader));

    tableSubInfo.addCell(
            prepareSubCell((change.getWbsnode() != null ? change.getWbsnode().getName() : ""), fontCell));
    tableSubInfo.addCell(prepareSubCell(
            (change.getEstimatedEffort() != null ? String.valueOf(change.getEstimatedEffort()) : ""),
            fontCell));
    tableSubInfo.addCell(prepareSubCell(
            (change.getEstimatedCost() != null ? ValidateUtil.toCurrency(change.getEstimatedCost()) : ""),
            fontCell));

    PdfPCell subTable = new PdfPCell(tableSubInfo);
    subTable.setBorderWidth(1F);

    tableInfo.addCell(subTable);

    tableInfo.addCell(prepareHeaderCell(idioma.getString("change.impact_desc"), fontHeader, 1F, 1F, 0F, 1F));
    tableInfo.addCell(prepareCell(change.getImpactDescription(), fontCell, 0F, 1F, 1F, 1F));

    document.add(tableInfo);

    document.add(new Paragraph(idioma.getString("change.resolution")));

    PdfPTable tableResolution = new PdfPTable(1);
    tableResolution.setWidthPercentage(100);
    tableResolution.setSpacingBefore(10);
    tableResolution.setSpacingAfter(15);

    tableResolution
            .addCell(prepareHeaderCell(idioma.getString("change.resolution"), fontHeader, 1F, 1F, 0F, 1F));
    tableResolution.addCell(
            prepareCell((change.getResolution() != null && change.getResolution() ? idioma.getString("yes")
                    : idioma.getString("no")), fontCell, 0F, 1F, 0F, 1F));

    tableResolution
            .addCell(prepareHeaderCell(idioma.getString("change.resolution_date"), fontHeader, 1F, 1F, 0F, 1F));
    tableResolution.addCell(
            prepareCell(DateUtil.format(idioma, change.getResolutionDate()), fontCell, 0F, 1F, 0F, 1F));

    tableResolution.addCell(
            prepareHeaderCell(idioma.getString("change.resolution_reason"), fontHeader, 1F, 1F, 0F, 1F));
    tableResolution.addCell(prepareCell(change.getResolutionReason(), fontCell, 0F, 1F, 1F, 1F));

    document.add(tableResolution);

    document.close();

    try {

        PdfReader reader = new PdfReader(outputStream.toByteArray());
        PdfStamper stamper = new PdfStamper(reader, outputStream);

        int numPag = reader.getNumberOfPages();

        for (int i = 1; i <= reader.getNumberOfPages(); i++) {
            setHeaderFooter(i, numPag, headerImg, footerImg, reader, stamper, idioma);
        }

        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    file = outputStream.toByteArray();

    return file;
}

From source file:essencialles.modelos.relatorio.tipos.MaisVendidos.java

@Override
public void run() {
    try {//from   w  w w .  j a v  a 2  s. c  o m
        //criao do PDF
        Document doc = new Document(PageSize.A4, 72, 72, 72, 72);

        OutputStream saida = new FileOutputStream(this.caminho);
        PdfWriter.getInstance(doc, saida);
        doc.open();
        try {
            //logomarca
            Image img = Image.getInstance("src/views/img/logomarca.png");
            img.setAlignment(Element.ALIGN_CENTER);
            doc.add(img);
        } catch (BadElementException | IOException ex) {
            throw new RuntimeException(ex);
        }
        //paragrafo
        Paragraph paragrafo = new Paragraph("Relatrio de Produtos Mais Vendidos");
        paragrafo.setSpacingAfter(50);
        paragrafo.setSpacingBefore(15);
        paragrafo.setFont(new Font(Font.FontFamily.COURIER, Font.BOLD));
        paragrafo.setAlignment(Element.ALIGN_CENTER);
        doc.add(paragrafo);

        /*tabela
         PdfPTable tabela = new PdfPTable(9);
         tabela.setHorizontalAlignment(Element.ALIGN_CENTER);
         PdfPCell header = new PdfPCell(new Paragraph("Todos os Produtos"));
         header.setColspan(9);
         tabela.addCell(header);
         tabela.addCell("Codigo");
         tabela.addCell("Nome");
         tabela.addCell("Marca");
         tabela.addCell("Preo");
         tabela.addCell("Custo");
         tabela.addCell("Cor");
         tabela.addCell("Descrio");
         tabela.addCell("Peso");
         tabela.addCell("Disponibilidade");
         tabela.addCell("Validade");
         adicionar linhas da tabela.
         for (Produto p : produtos) {
         String cod = p.getCod_produto() + "";
         String nome = p.getNome();
         String marca = p.getMarca();
         String preco = p.getPreco() + "";
         String custo = p.getCusto() + "";
         String cor = p.getCor();
         String descricao = p.getDescricao();
         String peso = p.getPeso();
         String disponibilidade = p.getDisponibilidade();
         String validade = p.getValidade() + "";
                
         }*/
        try {
            saida.flush();

        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        doc.close();

        try {
            saida.close();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }

    } catch (FileNotFoundException | DocumentException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:essencialles.modelos.relatorio.tipos.ProdutosTodos.java

@Override
public void run() {

    try {/* w  w  w .  j  a  v a 2s .c o  m*/
        //criao do PDF

        Document doc = new Document(PageSize.A4, 72, 72, 72, 72);

        OutputStream saida = new FileOutputStream(this.caminho);
        PdfWriter.getInstance(doc, saida);
        doc.open();
        try {
            //logomarca

            Image img = Image.getInstance("src/views/img/logomarca.png");
            img.setAlignment(Element.ALIGN_CENTER);
            doc.add(img);
        } catch (BadElementException | IOException ex) {
            throw new RuntimeException(ex);
        }
        //paragrafo
        Paragraph paragrafo = new Paragraph("Relatrio de Produtos");
        paragrafo.setSpacingAfter(50);
        paragrafo.setSpacingBefore(15);
        paragrafo.setFont(new Font(Font.FontFamily.COURIER, Font.BOLD));
        paragrafo.setAlignment(Element.ALIGN_CENTER);
        doc.add(paragrafo);

        /*tabela
         PdfPTable tabela = new PdfPTable(9);
         tabela.setHorizontalAlignment(Element.ALIGN_CENTER);
         PdfPCell header = new PdfPCell(new Paragraph("Todos os Produtos"));
         header.setColspan(9);
         tabela.addCell(header);
         tabela.addCell("Codigo");
         tabela.addCell("Nome");
         tabela.addCell("Marca");
         tabela.addCell("Preo");
         tabela.addCell("Custo");
         tabela.addCell("Cor");
         tabela.addCell("Descrio");
         tabela.addCell("Peso");
         tabela.addCell("Disponibilidade");
         tabela.addCell("Validade");
         adicionar linhas da tabela.
         for (ProdutoModelo p : produtos) {
         String cod = p.getCod_produto() + "";
         String nome = p.getNome();
         String marca = p.getMarca();
         String preco = p.getPreco() + "";
         String custo = p.getCusto() + "";
         String cor = p.getCor();
         String descricao = p.getDescricao();
         String peso = p.getPeso();
         String disponibilidade = p.getDisponibilidade();
         String validade = p.getValidade() + "";
                
         }*/
        try {
            saida.flush();

        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        doc.close();

        try {
            saida.close();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }

    } catch (FileNotFoundException | DocumentException ex) {
        throw new RuntimeException(ex);
    }

}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java

License:Open Source License

protected Paragraph getDefaultParagraph() {

    Paragraph result = new Paragraph();
    result.setFont(CONTENT_NORMAL);//from   w ww.java  2s  .  c o m
    result.setAlignment(Element.ALIGN_JUSTIFIED);
    result.setSpacingAfter(result.getFont().getSize() * 1.5f);
    return result;
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java

License:Open Source License

protected Phrase getDefaultPhrase() {

    Paragraph result = new Paragraph();
    result.setFont(CONTENT_NORMAL);//from   w  w  w .  j  a  va  2 s.  c  o m
    result.setAlignment(Element.ALIGN_JUSTIFIED);
    result.setSpacingAfter(result.getFont().getSize() * 1.5f);
    return result;
}