Example usage for com.itextpdf.text Document add

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

Introduction

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

Prototype


public boolean add(Element element) throws DocumentException 

Source Link

Document

Adds an Element to the Document.

Usage

From source file:com.raghav.plot.ImageIntoPDF.java

public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A4);

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("/home/raghav/zzzzz.pdf"));
    document.open();//w w  w  . ja  v  a 2 s  . c  o  m
    document.newPage();

    //for 4 photo
    //        for (int i=0;i<2;i++) {
    //            Image image1 = Image.getInstance("/home/raghav/Desktop/Firmway-Reco.png");
    //            image1.setAbsolutePosition(40,80+(350*i));
    //          image1.scaleAbsolute(200, 260);
    //            document.add(image1);
    //        }
    //          for (int i=0;i<2;i++) {
    //            Image image1 = Image.getInstance("/home/raghav/Desktop/Firmway-Reco.png");
    //            image1.setAbsolutePosition(300, 80+(350*i));
    //          image1.scaleAbsolute(260, 200);
    //            document.add(image1);
    //        }
    //for 6

    float margin = 10;

    float docHeight = ((document.getPageSize().getHeight()) / 3) - (2 * margin);
    float docwidth = ((document.getPageSize().getWidth()) / 2) - (2 * margin);

    for (int i = 0; i < 3; i++) {
        Image image1 = Image.getInstance("/home/raghav/myps/i1.jpeg");

        image1.setAbsolutePosition(margin, margin * (i + 1) + (docHeight * i));
        image1.scaleToFit(docwidth, docHeight);
        //image1.scaleAbsolute(190, 130);
        document.add(image1);
    }
    for (int i = 0; i < 3; i++) {
        Image image1 = Image.getInstance("/home/raghav/myps/i1.jpeg");
        image1.setAbsolutePosition(docwidth + (2 * margin), margin * (i + 1) + (docHeight * i));
        image1.scaleToFit(docwidth, docHeight);
        document.add(image1);
    }
    document.close();
}

From source file:com.rapidminer.gui.actions.ExportPdfAction.java

License:Open Source License

/**
 * Creates a pdf showing the given {@link Component} via {@link PdfTemplate} usage.
 * @param component//from   w  w  w.  ja  v  a  2s  . co m
 * @param document
 * @param cb
 * @throws DocumentException
 */
private void createPdfViaTemplate(Component component, Document document, PdfContentByte cb)
        throws DocumentException {
    PdfTemplate tp = cb.createTemplate(500, PageSize.A4.getHeight() / 2);
    Graphics2D g2 = tp.createGraphics(500, PageSize.A4.getHeight() / 2);

    // special handling for charts as we only want to export the chart but not the control panel
    // chart cannot be scaled to size of component because otherwise we would break the chart aspect-ratio
    if (component.getClass().isAssignableFrom(JPanel.class)) {
        JPanel panel = (JPanel) component;
        if (panel.getLayout().getClass().isAssignableFrom(CardLayout.class)) {
            for (final Component comp : panel.getComponents()) {
                // iterate over all card components and see if there is a chart which would require special handling
                // if not we don't do anything in this loop and do the standard behavior at the bottom of the method
                if (comp.isVisible() && ChartConfigurationPanel.class.isAssignableFrom(comp.getClass())) {
                    final ChartConfigurationPanel chartConfigPanel = (ChartConfigurationPanel) comp;

                    // create new LinkAndBrushChartPanel with double buffering set to false to get vector graphic export
                    // The real chart has to use double buffering for a) performance and b) zoom rectangle drawing
                    LinkAndBrushChartPanel newLaBPanel = new LinkAndBrushChartPanel(
                            chartConfigPanel.getPlotEngine().getChartPanel().getChart(),
                            chartConfigPanel.getPlotEngine().getChartPanel().getWidth(),
                            chartConfigPanel.getPlotEngine().getChartPanel().getHeight(),
                            chartConfigPanel.getPlotEngine().getChartPanel().getMinimumDrawWidth(),
                            chartConfigPanel.getPlotEngine().getChartPanel().getMinimumDrawHeight(), false,
                            false);
                    newLaBPanel.setSize(chartConfigPanel.getPlotEngine().getChartPanel().getSize());
                    newLaBPanel
                            .setOverlayList(chartConfigPanel.getPlotEngine().getChartPanel().getOverlayList());
                    AffineTransform at = new AffineTransform();
                    double factor = 500d / chartConfigPanel.getPlotEngine().getChartPanel().getWidth();
                    at.scale(factor, factor);
                    g2.transform(at);
                    newLaBPanel.print(g2);
                    g2.dispose();
                    document.add(new Paragraph(componentName));
                    document.add(Image.getInstance(tp));

                    return;
                } else if (comp.isVisible() && PlotterPanel.class.isAssignableFrom(comp.getClass())) {
                    // special case for PlotterPanel as the Panel itself is wider than the plotter
                    // not having a special case here results in the exported image being too wide (empty space to the left)
                    final PlotterPanel plotterPanel = (PlotterPanel) comp;

                    AffineTransform at = new AffineTransform();
                    double factor = 500d / plotterPanel.getPlotterComponent().getWidth();
                    at.scale(factor, factor);
                    g2.transform(at);
                    plotterPanel.print(g2);
                    g2.dispose();
                    document.add(new Paragraph(componentName));
                    document.add(Image.getInstance(tp));

                    return;
                }
            }
        }
    }

    AffineTransform at = new AffineTransform();
    double factor = 500d / component.getWidth();
    at.scale(factor, factor);
    g2.transform(at);
    component.print(g2);
    g2.dispose();
    document.add(new Paragraph(componentName));
    document.add(Image.getInstance(tp));
}

From source file:com.rapidminer.gui.actions.ExportPdfAction.java

License:Open Source License

/**
 * Creates a pdf showing the given {@link PlotterTemplate} via {@link PdfTemplate} usage.
 * @param template//from   ww w  . jav a  2 s .c o m
 * @param document
 * @param cb
 * @throws DocumentException
 */
private void createPdfViaTemplate(PlotterTemplate template, Document document, PdfContentByte cb)
        throws DocumentException {
    PdfTemplate tp = cb.createTemplate(500, PageSize.A4.getHeight() / 2);
    Graphics2D g2 = tp.createGraphics(500, PageSize.A4.getHeight() / 2);
    AffineTransform at = new AffineTransform();
    double factor = 500d / template.getPlotEngine().getChartPanel().getWidth();
    at.scale(factor, factor);
    g2.transform(at);
    template.getPlotEngine().getChartPanel().print(g2);
    g2.dispose();
    document.add(new Paragraph(componentName));
    document.add(Image.getInstance(tp));
}

From source file:com.sample.biblio.fe.core.controller.ReportBean.java

@PostConstruct
public void init() {
    try {//  w w w.  j  a  va 2  s .  c  om
        //----------------------------------
        Document doc = new Document();

        OutputStream out = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(doc, out);

        doc.open();
        doc.add(new Paragraph("Hello World. ok........"));
        doc.close();
        out.close();

        InputStream in = new ByteArrayInputStream(((ByteArrayOutputStream) out).toByteArray());

        streamedContent = new DefaultStreamedContent(in, "application/pdf");
        //-------
        Map<String, Object> session = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
        byte[] b = (byte[]) session.get("reportBytes");
        if (b != null) {
            streamedContent = new DefaultStreamedContent(new ByteArrayInputStream(b), "application/pdf");
        }
    } catch (Exception e) {
    }

}

From source file:com.sapito.direccion.PdfBuildertextV.java

@Override
protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter pdfWriter,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    Font font1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 30);
    font1.setColor(BaseColor.BLACK);/*from   w  w  w .  j av a 2 s. c om*/
    Font font2 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 24);
    font2.setColor(BaseColor.BLACK);
    document.add(new Paragraph("TAILS 2015", font1));
    document.add(new Paragraph("Reportes Direccin\n", font2));
    TextoPdf x = (TextoPdf) model.get("todoTexto");
    //        System.out.println(x.getTodoTexto());
    document.add(new Paragraph(x.getTodoTexto()));
    //
    //        List<Book> listBooks = (List<Book>) model.get("listBooks");
    //
    //        document.add(new Paragraph("\nReporte de Ventas\n"));
    //        PdfPTable table = new PdfPTable(2);
    //        table.setWidthPercentage(100.0f);
    //        table.setWidths(new float[]{3.0f, 2.0f});
    //        table.setSpacingBefore(10);
    //
    //        // define font for table header row
    //        Font font = FontFactory.getFont(FontFactory.COURIER_BOLD);
    //        font.setColor(BaseColor.WHITE);
    //
    //
    //        PdfPCell cell = new PdfPCell();
    //        cell.setBackgroundColor(BaseColor.BLUE);
    //        cell.setPadding(5);
    //
    //
    //        cell.setPhrase(new Phrase("Categoria", font));
    //        table.addCell(cell);
    //
    //        cell.setPhrase(new Phrase("Monto", font));
    //        table.addCell(cell);
    //        
    //
    //        document.add(table);

}

From source file:com.sapito.pdf.PDFView.PDFGeneratorActivosFijos.java

public void crearPDFInversion(HttpServletResponse hsr1, ArrayList<HashMap> resultados,
        double granTotalDepActual, double granTotalValorActual, double granTotalValorOr) throws Exception {
    Document dcmntaf = new Document();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(dcmntaf, baos);
    System.out.println(resultados.get(0).size());

    dcmntaf.open();//w ww.j  a  v a 2  s . co m
    dcmntaf.open();
    dcmntaf.addTitle("Sapito PDFs");
    dcmntaf.addSubject("Pdf de sapito");

    //------------------------ TAIS  ______________________________
    Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg"));
    dcmntaf.add(tais);

    //---------------------  BODY    ---------------------------------------------------------
    Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png"));
    body.setAlignment(Image.UNDERLYING);
    body.setTransparency(new int[] { 0x00, 0x10 });
    body.setAbsolutePosition(50, 250);
    dcmntaf.add(body);
    //-------------------------------------------------------------------------------------------
    Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg"));
    footer.setAbsolutePosition(50, 20);
    dcmntaf.add(footer);
    //----------------------  TITLE ---------------------------
    String titulo = "Reporte de Inversin"; //Cambiar el titulo del PDF aqui
    Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK);
    Chunk c = new Chunk(titulo + " \n ", f);
    c.setBackground(BaseColor.WHITE);
    Paragraph title = new Paragraph(c);
    title.setAlignment(Element.ALIGN_CENTER);

    String titulo2 = "Reporte de Activos Fijos por Tipo"; //Cambiar el titulo del PDF aqui
    Font f2 = new Font(FontFamily.HELVETICA, 12.0f, Font.NORMAL, BaseColor.BLACK);
    Chunk c2 = new Chunk(titulo2 + " \n ", f2);
    c2.setBackground(BaseColor.WHITE);
    Paragraph title2 = new Paragraph(c2);
    title2.setAlignment(Element.ALIGN_LEFT);
    title2.setIndentationLeft(50);
    //-------------------------  CONTENIDO -------------------------------------------------------
    dcmntaf.add(title); //Titulo del PDF
    dcmntaf.add(title2);
    PdfPTable table = new PdfPTable(4);

    //                                 PdfPCell cell;
    //                            cell = new PdfPCell(new Phrase("Tipo de A", FontFactory.getFont("TIMES_ROMAN", 12, Font.BOLD, BaseColor.BLACK)));                     
    //                        table.addCell(cell);      
    table.addCell("Tipo de Activo fijo");
    table.addCell("Valor Original");
    table.addCell("Depreciacin Actual ");
    table.addCell("Valor Actual");
    //        Iterator it = resultados.get(0).entrySet().iterator();
    for (int i = 0; i < resultados.size(); i++) {
        table.addCell(resultados.get(i).get("tipo").toString());
        table.addCell(resultados.get(i).get("valorOriginal").toString());
        table.addCell(resultados.get(i).get("depreciacionActual").toString());
        table.addCell(resultados.get(i).get("valoreActual").toString());
    }

    //        while (it.hasNext()) {
    //            Map.Entry e = (Map.Entry) it.next();
    //            System.out.println(e.getKey() + " " + e.getValue());
    //            
    //            table.addCell(e.getValue().toString());
    //        }

    dcmntaf.add(table);

    String titulo3 = "Reporte Total de Activos Fijos"; //Cambiar el titulo del PDF aqui
    Font f3 = new Font(FontFamily.HELVETICA, 12.0f, Font.NORMAL, BaseColor.BLACK);
    Chunk c3 = new Chunk(titulo3 + " \n ", f3);
    c3.setBackground(BaseColor.WHITE);

    Paragraph title3 = new Paragraph(c3);
    title3.setAlignment(Element.ALIGN_LEFT);
    title3.setIndentationLeft(50);
    dcmntaf.add(title3);

    PdfPTable table2 = new PdfPTable(3);
    //                                 PdfPCell cell;
    //                            cell = new PdfPCell(new Phrase("Tipo de A", FontFactory.getFont("TIMES_ROMAN", 12, Font.BOLD, BaseColor.BLACK)));                     
    //                        table.addCell(cell);                        
    table2.addCell("Valor Original Total");
    table2.addCell("Depreciacin Anual Total");
    table2.addCell("Valor Total");
    table2.addCell(granTotalValorOr + "");
    table2.addCell(granTotalDepActual + "");
    table2.addCell(granTotalValorActual + "");

    dcmntaf.add(table2);

    PdfPTable table3 = new PdfPTable(1);
    table3.setWidthPercentage(100.0f);
    table3.setWidths(new float[] { 2.0f });
    table3.setSpacingBefore(10);

    // define font for table header row
    Font font = FontFactory.getFont(FontFactory.COURIER_BOLD);
    font.setColor(BaseColor.WHITE);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    cell.setBackgroundColor(BaseColor.BLUE);
    cell.setPadding(5);

    // write table header 
    cell.setPhrase(new Phrase("Resultado", font));
    table3.addCell(cell);
    Depreciacion dep = new Depreciacion();

    String bla = a + " ";
    table3.addCell(bla);

    //-------------------------- FIN CONTENIDO -----------------
    dcmntaf.close();

    dcmntaf.close();

    byte[] bytes = baos.toByteArray();

    hsr1.setContentType("application/pdf");
    hsr1.setContentLength(bytes.length);
    hsr1.getOutputStream().write(bytes);
}

From source file:com.sapito.pdf.PDFView.PDFGeneratorContabilidad.java

public void crearEstadoResultados(HttpServletResponse hsr1, String ingresos, String cVenta, String cGeneral,
        String cImpu, String cImpTot) throws Exception {
    Document document = new Document();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);

    document.open();//  w  ww.j  a  va 2  s .c  o m
    document.addTitle("Sapito PDFs");
    document.addSubject("Pdf de sapito");

    //------------------------ TAIS  ______________________________
    Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg"));
    document.add(tais);

    //---------------------  BODY    ---------------------------------------------------------
    Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png"));
    body.setAlignment(Image.UNDERLYING);
    body.setTransparency(new int[] { 0x00, 0x10 });
    body.setAbsolutePosition(50, 250);
    document.add(body);
    //-------------------------------------------------------------------------------------------
    Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg"));
    footer.setAbsolutePosition(50, 20);
    document.add(footer);
    //----------------------  TITLE ---------------------------
    String titulo = "Estado de Resultados"; //Cambiar el titulo del PDF aqui
    Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK);
    Chunk c = new Chunk(titulo + " \n ", f);
    c.setBackground(BaseColor.WHITE);
    Paragraph title = new Paragraph(c);
    title.setAlignment(Element.ALIGN_CENTER);
    //-------------------------  CONTENIDO -------------------------------------------------------
    document.add(title); //Titulo del PDF
    PdfPTable table = new PdfPTable(2);

    table.addCell("Ingresos");
    table.addCell(ingresos);//valor
    table.addCell("Costo de Venta");
    table.addCell(cVenta);//valor
    table.addCell("Costos Generales");
    table.addCell(cGeneral);//valor
    table.addCell("Impuestos de Ingresos");
    table.addCell(cImpu);//valor
    table.addCell("Impuesto de Costos Totales");
    table.addCell(cImpTot);//valor
    document.add(table);
    document.close();

    byte[] bytes = baos.toByteArray();

    hsr1.setContentType("application/pdf");
    hsr1.setContentLength(bytes.length);
    hsr1.getOutputStream().write(bytes);
}

From source file:com.sapito.pdf.PDFView.PDFGeneratorContabilidad.java

public void crearVariacionContable(HttpServletResponse hsr1, String sInicial, String aumento, String utilidad,
        String disminucion, String perdidas, String sFinal) throws Exception {
    Document document = new Document();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);

    document.open();/*w w  w .  j ava2 s.  c  om*/
    document.addTitle("Sapito PDFs");
    document.addSubject("Pdf de sapito");

    //------------------------ TAIS  ______________________________
    Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg"));
    document.add(tais);

    //---------------------  BODY    ---------------------------------------------------------
    Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png"));
    body.setAlignment(Image.UNDERLYING);
    body.setTransparency(new int[] { 0x00, 0x10 });
    body.setAbsolutePosition(50, 250);
    document.add(body);
    //-------------------------------------------------------------------------------------------
    Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg"));
    footer.setAbsolutePosition(50, 20);
    document.add(footer);
    //----------------------  TITLE ---------------------------
    String titulo = "Variaciones de Capital Contable"; //Cambiar el titulo del PDF aqui
    Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK);
    Chunk c = new Chunk(titulo + " \n ", f);
    c.setBackground(BaseColor.WHITE);
    Paragraph title = new Paragraph(c);
    title.setAlignment(Element.ALIGN_CENTER);
    //-------------------------  CONTENIDO -------------------------------------------------------
    document.add(title); //Titulo del PDF
    PdfPTable table = new PdfPTable(2);

    table.addCell("Saldo al inicio del ejercicio");
    table.addCell(sInicial);//valor
    table.addCell("Aumentos");
    table.addCell(aumento);//valor
    table.addCell("Utilidades");
    table.addCell(utilidad);//valor
    table.addCell("Disminuciones");
    table.addCell(disminucion);//valor
    table.addCell("Perdidas");
    table.addCell(perdidas);//valor
    table.addCell("Saldo al final del ejercicio");
    table.addCell(sFinal);//valor

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

    byte[] bytes = baos.toByteArray();

    hsr1.setContentType("application/pdf");
    hsr1.setContentLength(bytes.length);
    hsr1.getOutputStream().write(bytes);
}

From source file:com.sapito.pdf.PDFView.PDFGeneratorContabilidad.java

public void crearFlujo(HttpServletResponse hsr1, String operacion, String sInicio, String sFin)
        throws Exception {
    Document document = new Document();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);

    document.open();//from   w  ww  .  j  a va 2s.  c o m
    document.addTitle("Sapito PDFs");
    document.addSubject("Pdf de sapito");

    //------------------------ TAIS  ______________________________
    Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg"));
    document.add(tais);

    //---------------------  BODY    ---------------------------------------------------------
    Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png"));
    body.setAlignment(Image.UNDERLYING);
    body.setTransparency(new int[] { 0x00, 0x10 });
    body.setAbsolutePosition(50, 250);
    document.add(body);
    //-------------------------------------------------------------------------------------------
    Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg"));
    footer.setAbsolutePosition(50, 20);
    document.add(footer);
    //----------------------  TITLE ---------------------------
    String titulo = "Flujo de Efectivo"; //Cambiar el titulo del PDF aqui
    Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK);
    Chunk c = new Chunk(titulo + " \n ", f);
    c.setBackground(BaseColor.WHITE);
    Paragraph title = new Paragraph(c);
    title.setAlignment(Element.ALIGN_CENTER);
    //-------------------------  CONTENIDO -------------------------------------------------------
    document.add(title); //Titulo del PDF
    PdfPTable table = new PdfPTable(2);

    table.addCell("Operacin");
    table.addCell(operacion);//valor
    table.addCell("Saldo al inicio del ao");
    table.addCell(sInicio);//valor
    table.addCell("Saldo al inicio del ao");
    table.addCell(sFin);//valor
    document.add(table);

    document.close();

    byte[] bytes = baos.toByteArray();

    hsr1.setContentType("application/pdf");
    hsr1.setContentLength(bytes.length);
    hsr1.getOutputStream().write(bytes);
}

From source file:com.sapito.pdf.PDFView.PDFGeneratorContabilidad.java

public void crearBalance(HttpServletResponse hsr1, String aCirculante, String aNCirculante, String tActivos,
        String pasivo) throws Exception {
    Document document = new Document();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);

    document.open();/*  w ww . j  a va 2  s . co m*/
    document.addTitle("Sapito PDFs");
    document.addSubject("Pdf de sapito");

    //------------------------ TAIS  ______________________________
    Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg"));
    document.add(tais);

    //---------------------  BODY    ---------------------------------------------------------
    Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png"));
    body.setAlignment(Image.UNDERLYING);
    body.setTransparency(new int[] { 0x00, 0x10 });
    body.setAbsolutePosition(50, 250);
    document.add(body);
    //-------------------------------------------------------------------------------------------
    Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg"));
    footer.setAbsolutePosition(50, 20);
    document.add(footer);
    //----------------------  TITLE ---------------------------
    String titulo = "Balance General"; //Cambiar el titulo del PDF aqui
    Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK);
    Chunk c = new Chunk(titulo + " \n ", f);
    c.setBackground(BaseColor.WHITE);
    Paragraph title = new Paragraph(c);
    title.setAlignment(Element.ALIGN_CENTER);
    //-------------------------  CONTENIDO -------------------------------------------------------
    document.add(title); //Titulo del PDF
    PdfPTable table = new PdfPTable(2);

    table.addCell("Activo circulante");
    table.addCell(aCirculante);//valor
    table.addCell("Activo no circulante");
    table.addCell(aNCirculante);//valor
    table.addCell("total activos");
    table.addCell(tActivos);//valor
    table.addCell("pasivo");
    table.addCell(pasivo);//valor
    document.add(table);

    document.close();

    byte[] bytes = baos.toByteArray();

    hsr1.setContentType("application/pdf");
    hsr1.setContentLength(bytes.length);
    hsr1.getOutputStream().write(bytes);
}