Example usage for com.lowagie.text Document addAuthor

List of usage examples for com.lowagie.text Document addAuthor

Introduction

In this page you can find the example usage for com.lowagie.text Document addAuthor.

Prototype


public boolean addAuthor(String author) 

Source Link

Document

Adds the author to a Document.

Usage

From source file:proyecto.Main.java

private void cr_red_guardarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cr_red_guardarMouseClicked
    JFileChooser jfc = new JFileChooser();
    FileFilter filtro = new FileNameExtensionFilter("PNG", "png");
    FileFilter filtro2 = new FileNameExtensionFilter("JPG", "jpg");
    FileFilter filtro3 = new FileNameExtensionFilter("PDF", "pdf");
    FileFilter filtro4 = new FileNameExtensionFilter("JPEG", "jpeg");
    FileFilter filtro5 = new FileNameExtensionFilter("Dany", "dany");
    jfc.addChoosableFileFilter(filtro);/*from   w ww.  ja  v  a2 s.  c  om*/
    jfc.addChoosableFileFilter(filtro2);
    jfc.addChoosableFileFilter(filtro3);
    jfc.addChoosableFileFilter(filtro4);
    jfc.addChoosableFileFilter(filtro5);

    int op = jfc.showSaveDialog(jfc);

    if (op == JFileChooser.APPROVE_OPTION) {
        if (jfc.getFileFilter().getDescription().equals("PNG")) {
            try {
                BufferedImage bi = new BufferedImage(jp_red.getWidth(), jp_red.getHeight(),
                        BufferedImage.TYPE_INT_RGB);
                Graphics2D g = bi.createGraphics();
                jp_red.paint(g);
                File archivo = new File(jfc.getSelectedFile().toString() + ".png");
                ImageIO.write(bi, "png", archivo);
            } catch (Exception ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (jfc.getFileFilter().getDescription().equals("JPG")) {
            try {
                BufferedImage bi = new BufferedImage(jp_red.getWidth(), jp_red.getHeight(),
                        BufferedImage.TYPE_INT_RGB);
                Graphics2D g = bi.createGraphics();
                jp_red.paint(g);
                File archivo = new File(jfc.getSelectedFile().toString() + ".jpg");
                ImageIO.write(bi, "jpg", archivo);
            } catch (Exception ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (jfc.getFileFilter().getDescription().equals("PDF")) {
            try {
                Document documentPDF = new Document();
                PdfWriter pdf = PdfWriter.getInstance(documentPDF,
                        new FileOutputStream(jfc.getSelectedFile().getPath() + ".pdf"));
                documentPDF.open();

                documentPDF.addAuthor("Dany Cheong");
                documentPDF.addCreator("DC");

                BufferedImage bi = new BufferedImage(jp_red.getWidth(), jp_red.getHeight(),
                        BufferedImage.TYPE_INT_RGB);
                Graphics2D g = bi.createGraphics();
                jp_red.paint(g);
                File archivo = new File(jfc.getSelectedFile().toString() + ".png");
                ImageIO.write(bi, "png", archivo);
                documentPDF.add(com.lowagie.text.Image.getInstance(jfc.getSelectedFile().toString() + ".png"));
                archivo.delete();

                documentPDF.close();
            } catch (Exception ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (jfc.getFileFilter().getDescription().equals("JPEG")) {
            try {
                BufferedImage bi = new BufferedImage(jp_red.getWidth(), jp_red.getHeight(),
                        BufferedImage.TYPE_INT_RGB);
                Graphics2D g = bi.createGraphics();
                jp_red.paint(g);
                File archivo = new File(jfc.getSelectedFile().toString() + ".jpeg");
                ImageIO.write(bi, "jpeg", archivo);
            } catch (Exception ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (jfc.getFileFilter().getDescription().equals("Dany")) {
            if (jfc.getSelectedFile().exists()) {
                try {
                    File archivo = null;
                    archivo = new File(jfc.getSelectedFile().getPath());

                    FileInputStream fis = new FileInputStream(archivo);
                    ObjectInputStream ois = new ObjectInputStream(fis);
                    Pane_temp panel;
                    ArrayList<Pane_temp> lista2 = new ArrayList();
                    try {
                        while ((panel = (Pane_temp) ois.readObject()) != null) {
                            lista2.add(panel);
                        }
                    } catch (Exception e) {

                    } finally {
                        fis.close();
                        ois.close();
                    }

                    for (int i = 0; i < lista.size(); i++) {
                        lista2.add(lista.get(i));
                    }

                    FileOutputStream fos = new FileOutputStream(archivo);
                    ObjectOutputStream oos = new ObjectOutputStream(fos);

                    for (Pane_temp temporal : lista2) {
                        oos.writeObject(temporal);
                    }
                    oos.flush();
                    oos.close();
                    fos.close();
                } catch (Exception e) {

                }
            } else {
                File archivo = null;
                try {
                    archivo = new File(jfc.getSelectedFile().getPath() + ".dany");
                    //crear archivo que no existe
                    FileOutputStream fos = new FileOutputStream(archivo);
                    ObjectOutputStream oos = new ObjectOutputStream(fos);
                    for (int i = 0; i < lista.size(); i++) {
                        oos.writeObject(lista.get(i));
                    }
                    oos.flush();
                    fos.close();
                    oos.close();
                    lista.removeAll(lista);
                } catch (Exception ex) {
                    ex.printStackTrace();
                } finally {

                }
            }
        }

    }
}

From source file:proyecto.Main.java

private void cr_organigrama_guardarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cr_organigrama_guardarMouseClicked
    JFileChooser jfc = new JFileChooser();
    FileFilter filtro = new FileNameExtensionFilter("PNG", "png");
    FileFilter filtro2 = new FileNameExtensionFilter("JPG", "jpg");
    FileFilter filtro3 = new FileNameExtensionFilter("PDF", "pdf");
    FileFilter filtro4 = new FileNameExtensionFilter("JPEG", "jpeg");
    FileFilter filtro5 = new FileNameExtensionFilter("Dany", "dany");
    jfc.addChoosableFileFilter(filtro);//  w  ww .j a  v a  2s . co  m
    jfc.addChoosableFileFilter(filtro2);
    jfc.addChoosableFileFilter(filtro3);
    jfc.addChoosableFileFilter(filtro4);
    jfc.addChoosableFileFilter(filtro5);

    int op = jfc.showSaveDialog(jfc);

    if (op == JFileChooser.APPROVE_OPTION) {
        if (jfc.getFileFilter().getDescription().equals("PNG")) {
            try {
                BufferedImage bi = new BufferedImage(jp_organigrama.getWidth(), jp_organigrama.getHeight(),
                        BufferedImage.TYPE_INT_RGB);
                Graphics2D g = bi.createGraphics();
                jp_organigrama.paint(g);
                File archivo = new File(jfc.getSelectedFile().toString() + ".png");
                ImageIO.write(bi, "png", archivo);
            } catch (Exception ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (jfc.getFileFilter().getDescription().equals("JPG")) {
            try {
                BufferedImage bi = new BufferedImage(jp_organigrama.getWidth(), jp_organigrama.getHeight(),
                        BufferedImage.TYPE_INT_RGB);
                Graphics2D g = bi.createGraphics();
                jp_organigrama.paint(g);
                File archivo = new File(jfc.getSelectedFile().toString() + ".jpg");
                ImageIO.write(bi, "jpg", archivo);
            } catch (Exception ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (jfc.getFileFilter().getDescription().equals("PDF")) {
            try {
                Document documentPDF = new Document();
                PdfWriter pdf = PdfWriter.getInstance(documentPDF,
                        new FileOutputStream(jfc.getSelectedFile().getPath() + ".pdf"));
                documentPDF.open();

                documentPDF.addAuthor("Dany Cheong");
                documentPDF.addCreator("DC");

                BufferedImage bi = new BufferedImage(jp_organigrama.getWidth(), jp_organigrama.getHeight(),
                        BufferedImage.TYPE_INT_RGB);
                Graphics2D g = bi.createGraphics();
                jp_organigrama.paint(g);
                File archivo = new File(jfc.getSelectedFile().toString() + ".png");
                ImageIO.write(bi, "png", archivo);
                documentPDF.add(com.lowagie.text.Image.getInstance(jfc.getSelectedFile().toString() + ".png"));
                archivo.delete();

                documentPDF.close();
            } catch (Exception ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (jfc.getFileFilter().getDescription().equals("JPEG")) {
            try {
                BufferedImage bi = new BufferedImage(jp_organigrama.getWidth(), jp_organigrama.getHeight(),
                        BufferedImage.TYPE_INT_RGB);
                Graphics2D g = bi.createGraphics();
                jp_organigrama.paint(g);
                File archivo = new File(jfc.getSelectedFile().toString() + ".jpeg");
                ImageIO.write(bi, "jpeg", archivo);
            } catch (Exception ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (jfc.getFileFilter().getDescription().equals("Dany")) {
            if (jfc.getSelectedFile().exists()) {
                try {
                    File archivo = null;
                    archivo = new File(jfc.getSelectedFile().getPath());

                    FileInputStream fis = new FileInputStream(archivo);
                    ObjectInputStream ois = new ObjectInputStream(fis);
                    Pane_temp panel;
                    ArrayList<Pane_temp> lista2 = new ArrayList();
                    try {
                        while ((panel = (Pane_temp) ois.readObject()) != null) {
                            lista2.add(panel);
                        }
                    } catch (Exception e) {

                    } finally {
                        fis.close();
                        ois.close();
                    }

                    for (int i = 0; i < lista.size(); i++) {
                        lista2.add(lista.get(i));
                    }

                    FileOutputStream fos = new FileOutputStream(archivo);
                    ObjectOutputStream oos = new ObjectOutputStream(fos);

                    for (Pane_temp temporal : lista2) {
                        oos.writeObject(temporal);
                    }
                    oos.flush();
                    oos.close();
                    fos.close();
                } catch (Exception e) {

                }
            } else {
                File archivo = null;
                try {
                    archivo = new File(jfc.getSelectedFile().getPath() + ".dany");
                    //crear archivo que no existe
                    FileOutputStream fos = new FileOutputStream(archivo);
                    ObjectOutputStream oos = new ObjectOutputStream(fos);
                    for (int i = 0; i < lista.size(); i++) {
                        oos.writeObject(lista.get(i));
                    }
                    oos.flush();
                    fos.close();
                    oos.close();
                    lista.removeAll(lista);
                } catch (Exception ex) {
                    ex.printStackTrace();
                } finally {

                }
            }
        }

    }
}

From source file:questions.metadata.ReplaceXMP.java

@SuppressWarnings("unchecked")
public static void createOriginal() {
    // step 1://from w  w  w . j a v a 2 s  . c o  m
    Document document = new Document();
    try {
        document.addAuthor("Bruno Lowagie");
        document.addKeywords("Hello World, XMP, Metadata");
        // step 2:
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(ORIGINAL));
        // step 3:
        writer.createXmpMetadata();
        document.open();
        // step 4:
        document.add(new Paragraph("Hello World"));
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    // step 5:
    document.close();
}

From source file:questions.metadata.UpdateModDate.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from ww  w .ja  va 2 s . c  o  m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(ORIGINAL));
        document.addTitle("Hello World example");
        document.addSubject("This example shows how to add metadata");
        document.addKeywords("Metadata, iText, XMP");
        document.addCreator("My program using iText");
        document.addAuthor("Bruno Lowagie");
        writer.createXmpMetadata();
        document.open();
        document.add(new Paragraph("Hello World"));
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    PdfReader reader;
    try {
        reader = new PdfReader(ORIGINAL);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(MODIFIED));
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:rollyroll.com.servlet.ModuloServlet.java

private void exportar_ModulosaPDF(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    try {//from  ww w  .j ava2 s .  c o  m
        //            String[] headers = new String[]{"CODIGO", "NOMBRE", "ACCION", "ORDEN", "ICONO", "ESTADO"};
        String[] headers = new String[] { "NOMBRE", "ACCION", "ICONO" };

        ArrayList<Modulo> lista = null;
        lista = moduloService.listar_Modulos();

        PdfPTable table = new PdfPTable(headers.length);
        table.setHorizontalAlignment(0);
        table.setWidthPercentage(95);
        float[] espaciocolumna = new float[] { 25f, 38f, 50f };
        table.setWidths(espaciocolumna);
        for (int i = 0; i < headers.length; i++) {
            String header = headers[i];
            PdfPCell cell = new PdfPCell();
            cell.setBackgroundColor(Color.YELLOW);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setPhrase(new Phrase(header.toUpperCase(), new Font(Font.HELVETICA, 10, Font.BOLD)));
            table.addCell(cell);
        }
        table.completeRow();
        PdfPCell cell;

        //            int codigomodulo = 0;
        String nombremodulo = "";
        String accionmodulo = "";
        //            int ordenmodulo = 0;
        String iconomodulo = "";
        //            int estadomodulo = 0;

        for (Modulo modulo : lista) {
            //                codigomodulo += Integer.parseInt(modulo.getCodigomodulo());
            nombremodulo += modulo.getNombremodulo();
            accionmodulo += modulo.getAccionmodulo();
            //                ordenmodulo += Integer.parseInt(modulo.getOrdenmoduloS());
            iconomodulo += modulo.getIconomodulo();
            //                estadomodulo += Byte.parseByte(modulo.getEstadomoduloS());

            //                cell = new PdfPCell();
            //                cell.setPhrase(new Phrase(modulo.getCodigomoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            //                cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            //                table.addCell(cell);
            //                
            cell = new PdfPCell();
            cell.setPhrase(new Phrase(modulo.getNombremodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            table.addCell(cell);

            cell = new PdfPCell();
            cell.setPhrase(new Phrase(modulo.getAccionmodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            table.addCell(cell);

            //                cell = new PdfPCell();
            //                cell.setPhrase(new Phrase(modulo.getOrdenmoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            //                cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            //                table.addCell(cell);
            cell = new PdfPCell();
            cell.setPhrase(new Phrase(modulo.getIconomodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            table.addCell(cell);

            //                cell = new PdfPCell();
            //                cell.setPhrase(new Phrase(modulo.getEstadomoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            //                cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            //                table.addCell(cell);
        }

        table.completeRow();

        //incia diseo de documento exportado
        Document document = new Document(PageSize.A4.rotate(), 20, 5, 5, 5);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);
        document.open();

        document.addTitle("Reporte de Ventas Generales");
        document.add(
                new Paragraph("Reporte: Ventas Generales 2016", new Font(Font.HELVETICA, 16, Font.UNDERLINE)));
        document.add(new Paragraph("_"));
        document.add(table);
        document.add(Chunk.NEWLINE);
        document.add(new Paragraph(
                "Leyenda: AB: Inicio, BA: Retorno (Importante: No se consideran unidades sin GPS)"));
        document.addAuthor("Quispe Roque Alex Christian");

        table = new PdfPTable(4);
        table.setHorizontalAlignment(0);
        table.setWidthPercentage(40);
        espaciocolumna = new float[] { 10f, 40f, 20f, 20f };
        table.setWidths(espaciocolumna);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setPhrase(new Phrase("RESUMEN", new Font(Font.HELVETICA, 10, Font.BOLD)));
        cell.setColspan(7);
        table.addCell(cell);
        table.completeRow();

        //aqui iniciamos asignacion de datos
        //===================================================================
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setBackgroundColor(Color.yellow);
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("FLOTA OPERATIVA", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase(lista.size() + "", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("UNIDADES", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //            table.completeRow();
        //
        //            //==================================================================================
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("2", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setBackgroundColor(Color.yellow);
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("NRO DE VIAJES", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase((totalAB + totalBA) + "", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("VIAJES", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            table.completeRow();
        //==================================================================================
        document.add(Chunk.NEWLINE);
        document.add(table);

        document.left(1);
        document.top(1);
        document.close();
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        //            response.setHeader("Content-Disposition", "attachment; filename=ReporteGeneraldeModulos.pdf");
        response.setHeader("Content-Disposition", "filename=ReporteGeneraldeModulos.pdf");
        response.setHeader("Pragma", "public");
        response.setContentType("application/pdf");
        response.setContentLength(baos.size());
        ServletOutputStream out = response.getOutputStream();
        baos.writeTo(out);
        out.flush();

    } catch (Exception e) {
        RequestDispatcher rd2;
        rd2 = request.getRequestDispatcher("vista/include/error_404.jsp");
        rd2.forward(request, response);
        System.out.println(
                "rollyroll.com.servlet.ModuloServlet.exportar_ModulosaPDF() => ERROR GRAVE AL GENERAR PDF");
        e.getMessage();
    }
}

From source file:se.idega.idegaweb.commune.school.business.StudentAddressLabelsWriter.java

License:Open Source License

/**
 * Creates PDF address labels for the specified school classes.
 */// ww  w . j  av  a 2 s .  c o  m
protected MemoryFileBuffer getPDFBuffer(IWApplicationContext iwac, Collection receivers) throws Exception {
    this.business = getSchoolCommuneBusiness(iwac);
    this.userBusiness = getCommuneUserBusiness(iwac);

    IWResourceBundle iwrb = iwac.getIWMainApplication().getBundle(CommuneBlock.IW_BUNDLE_IDENTIFIER)
            .getResourceBundle(iwac.getApplicationSettings().getApplicationLocale());

    MemoryFileBuffer buffer = new MemoryFileBuffer();
    MemoryOutputStream mos = new MemoryOutputStream(buffer);

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    PdfWriter writer = PdfWriter.getInstance(document, mos);

    document.addTitle("Student address labels");
    document.addAuthor("Idega Reports");
    document.addSubject("Student address labels");
    document.open();

    this.font = new Font(Font.HELVETICA, 9, Font.BOLD);

    int studentCount = 0;

    Iterator iter = receivers.iterator();
    while (iter.hasNext()) {
        if (studentCount > 0 && studentCount % NR_OF_ADDRESSES_PER_PAGE == 0) {
            document.newPage();
        }

        addAddress(writer, iwrb, (MailReceiver) iter.next(), studentCount++);
    }

    if (studentCount == 0) {
        throw new Exception("No students.");
    }

    document.close();

    writer.setPdfVersion(PdfWriter.VERSION_1_2);
    buffer.setMimeType(MIME_PDF);
    return buffer;
}

From source file:se.idega.idegaweb.commune.school.report.business.ReportPDFWriter.java

License:Open Source License

private MemoryFileBuffer getPDFBuffer() throws DocumentException {
    MemoryFileBuffer buffer = new MemoryFileBuffer();
    MemoryOutputStream mos = new MemoryOutputStream(buffer);

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    PdfWriter writer = PdfWriter.getInstance(document, mos);

    String titleKey = this._reportModel.getReportTitleLocalizationKey();
    String title = localize(titleKey, titleKey);
    this._normalFont = new Font(Font.HELVETICA, 7, Font.NORMAL);
    this._boldFont = new Font(Font.HELVETICA, 7, Font.BOLD);

    document.addTitle(title);//from w  w  w . ja v  a2 s.com
    document.addAuthor("Agura IT Reports");
    document.addSubject(title);
    document.open();

    String dateString = new Date(System.currentTimeMillis()).toString();

    document.add(new Phrase(title + " " + dateString + "\n\n", this._boldFont));
    document.add(new Phrase("\n", this._boldFont));

    int cols = this._reportModel.getColumnSize() + 1;
    Table table = new Table(cols);
    this._widths = new int[cols];
    for (int i = 0; i < cols; i++) {
        this._widths[i] = 1;
    }

    table.setSpacing(1.5f);

    buildColumnHeaders(table);
    buildRowHeaders(table);
    buildReportCells(table);

    int totalWidth = 0;
    for (int i = 0; i < cols; i++) {
        this._widths[i] += 1;
        totalWidth += this._widths[i];
    }
    int width = (100 * totalWidth) / 95;
    if (width > 100) {
        width = 100;
    }
    table.setWidth(width);
    table.setWidths(this._widths);
    document.add(table);
    document.close();
    writer.setPdfVersion(PdfWriter.VERSION_1_2);

    return buffer;
}

From source file:sim.util.media.chart.ChartGenerator.java

License:Academic Free License

void generatePDF(JFreeChart chart, int width, int height, String fileName) {
    try {//from w w w.j  a  va 2  s.c  o  m
        Document document = new Document(new com.lowagie.text.Rectangle(width, height));
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
        document.addAuthor("MASON");
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(width, height);
        Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper());
        Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height);
        chart.draw(g2, rectangle2D);
        g2.dispose();
        cb.addTemplate(tp, 0, 0);
        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}