Classes.GerarPdf.java Source code

Java tutorial

Introduction

Here is the source code for Classes.GerarPdf.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Classes;

import Classes.Banco;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.File;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Paulo
 */
public class GerarPdf {

    Banco ba = new Banco();

    public static void main(String arg[]) throws Exception {

        File arquivo = new File("odontograma.pdf");

        System.out.print(arquivo.getAbsolutePath());

        File file = new File(arquivo.getAbsolutePath());
        file.delete();

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("odontograma.pdf"));
        document.open();
        document.add(new Paragraph("ODONTOGRAMA"));
        document.add(new Paragraph("\nCodigo Paciente: " + arg[0]));
        document.add(new Paragraph("Nome Paciente: " + arg[1]));
        document.add(new Paragraph("Codigo Procedimento: " + arg[2]));
        document.add(new Paragraph("Procedimento: " + arg[3]));
        document.add(new Paragraph("\nDetalhes : " + arg[4]));
        document.add(new Paragraph("\nValor : " + arg[5]));

        document.close();

    }

    public static void abrirPdf(String caminho) {
        try {
            java.awt.Desktop.getDesktop().open(new File(caminho));
        } catch (IOException ex) {
            Logger.getLogger(GerarPdf.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}