Example usage for com.itextpdf.text.pdf PdfContentByte setFontAndSize

List of usage examples for com.itextpdf.text.pdf PdfContentByte setFontAndSize

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfContentByte setFontAndSize.

Prototype

public void setFontAndSize(final BaseFont bf, final float size) 

Source Link

Document

Set the font and the size for the subsequent text writing.

Usage

From source file:Excel.pdfsJavaGenerador.java

public void run() {
    Document documento = new Document();
    documento.setPageSize(PageSize.A4.rotate());
    int i = 1;//w  w w .j a v  a2 s.  c om
    String arch = periodo + "_Iva Ventas.pdf";

    File fich = new File(arch);

    FileOutputStream fichero;
    try {
        pdfsJavaGenerador pdf;

        ArrayList listado = new ArrayList();
        String sql = "select * from ivaventas where periodo='" + periodo + "' order by numero";
        Transaccionable tra = new ConeccionLocal();
        ResultSet rs = tra.leerConjuntoDeRegistros(sql);
        while (rs.next()) {
            pdf = new pdfsJavaGenerador();
            pdf.setComprobante(rs.getString("comprobante"));
            pdf.setFecha(rs.getString("fecha"));
            pdf.setNumeroFactura(rs.getString("numero"));
            pdf.setRazonSocial(rs.getString("cliente"));
            pdf.setCondicionIva(rs.getString("condicion"));
            pdf.setCuit(rs.getString("cuit"));
            pdf.setNeto(rs.getString("neto"));
            pdf.setIva(rs.getString("iva"));
            pdf.setTotal(rs.getString("total"));
            listado.add(pdf);
        }
        rs.close();
        Integer totalItems = listado.size();
        Integer totalPaginas = totalItems / 46;
        Integer contadorPaginas = 1;
        totalPaginas = totalPaginas + 1;
        System.out.println(" items " + totalItems + " paginas " + totalPaginas);
        fichero = new FileOutputStream(arch);
        PdfWriter writer = PdfWriter.getInstance(documento, fichero);

        documento.open();
        //writer.addPageDictEntry(PdfName.ROTATE,PdfPage.SEASCAPE);
        writer.addPageDictEntry(PdfName.ROTATE, null);
        PdfContentByte cb = writer.getDirectContent();

        BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.setFontAndSize(bf, 12);
        cb.beginText();
        //cb.setTextMatrix(250,820);
        //cb.showText("Subdiario de IVA Ventas");
        cb.setFontAndSize(bf, 10);

        cb.setTextMatrix(20, 480);
        cb.showText("Periodo " + periodo);
        //cb.setTextMatrix(750,550);
        //cb.showText("Hoja "+contadorPaginas+" de "+totalPaginas);

        int renglon = 460;
        String vencimiento;
        String descripcion;
        String monto;
        String recargo;
        String total;
        String totalFinal;
        Double tot = 0.00;
        String razonSocial;
        int itt = 0;
        //aca empieza la iteracion

        //encabezados
        bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.setFontAndSize(bf, 8);
        cb.setTextMatrix(20, renglon);
        cb.showText("Cbte");
        cb.setTextMatrix(50, renglon);
        cb.showText("Fecha");
        cb.setTextMatrix(90, renglon);
        cb.showText("Nro Factura");
        cb.setTextMatrix(150, renglon);
        cb.showText("Cliente");
        cb.setTextMatrix(500, renglon);
        //tot=saldo.getCantidad() * saldo.getPrecioUnitario();
        cb.showText("Cond");
        cb.setTextMatrix(540, renglon);
        cb.showText("C.U.I.T.");
        cb.setTextMatrix(610, renglon);
        cb.showText("Neto");
        cb.setTextMatrix(660, renglon);
        cb.showText("I.V.A.");
        cb.setTextMatrix(700, renglon);
        cb.showText("Imp. Int.");
        cb.setTextMatrix(760, renglon);
        cb.showText("Total");
        renglon = renglon - 20;

        //fin encabezados
        bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.setFontAndSize(bf, 6);
        Iterator itl = listado.listIterator();
        //vencimiento="Esta cotizacin tendr vigencia 30 das ";
        Double montoCIva = 0.00;
        Double descuento = 0.00;
        Double descUnitario = 0.00;
        Double descTotal = 0.00;
        Double montoCIvaTotal = 0.00;
        Double descuentoTotal = 0.00;
        Double descUnitarioTotal = 0.00;
        Double descTotalTotal = 0.00;
        String descripcionArt = null;
        while (itl.hasNext()) {
            pdf = (pdfsJavaGenerador) itl.next();

            //vencimiento=saldo.getVencimientoString();
            /*
            descripcion="Numero Resumen de cta ";
            montoCIva=saldo.getPrecioUnitario() * 1.21;
            monto=Numeros.ConvertirNumero(montoCIva);
            recargo="10%";
            total="nada";
            */

            //recargo=String.valueOf(saldo.getRecargo());
            //tot=tot + saldo.getTotal();
            //total=String.valueOf(saldo.getTotal());

            cb.setTextMatrix(20, renglon);
            cb.showText(pdf.getComprobante());
            cb.setTextMatrix(45, renglon);
            cb.showText(pdf.getFecha());
            cb.setTextMatrix(90, renglon);
            cb.showText(pdf.getNumeroFactura());
            cb.setTextMatrix(150, renglon);

            razonSocial = pdf.getRazonSocial();

            cb.showText(razonSocial);
            cb.setTextMatrix(500, renglon);

            cb.showText(pdf.getCondicionIva());
            cb.setTextMatrix(540, renglon);
            cb.showText(pdf.getCuit());
            cb.setTextMatrix(600, renglon);

            if (pdf.getComprobante().equals("N.C.")) {
                String neto = pdf.getNeto();
                String iva = pdf.getIva();
                String totalP = pdf.getTotal();
                pdf.setNeto("-" + neto.trim());
                pdf.setIva("-" + iva.trim());
                pdf.setTotal("-" + totalP.trim());
            }
            montoCIva = montoCIva + Numeros.ConvertirStringADouble(pdf.getNeto());
            descuento = descuento + Numeros.ConvertirStringADouble(pdf.getIva());
            descTotal = descTotal + Numeros.ConvertirStringADouble(pdf.getTotal());

            cb.showText(pdf.getNeto());
            cb.setTextMatrix(650, renglon);

            cb.showText(pdf.getIva());
            cb.setTextMatrix(710, renglon);
            cb.showText("0.00");
            cb.setTextMatrix(750, renglon);

            cb.showText(pdf.getTotal());

            //descuento=descuento+saldo.getDescuento();
            renglon = renglon - 10;
            if (renglon < 30) {
                bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                cb.setFontAndSize(bf, 7);
                cb.setTextMatrix(550, renglon);
                cb.showText("Subtotal:");
                cb.setTextMatrix(600, renglon);
                cb.showText(Numeros.ConvetirNumeroDosDigitos(montoCIva));
                cb.setTextMatrix(650, renglon);
                cb.showText(Numeros.ConvetirNumeroDosDigitos(descuento));
                cb.setTextMatrix(710, renglon);
                cb.showText("0.00");
                cb.setTextMatrix(750, renglon);
                cb.showText(Numeros.ConvetirNumeroDosDigitos(descTotal));
                montoCIvaTotal = montoCIvaTotal + montoCIva;
                descuentoTotal = descuentoTotal + descuento;

                descTotalTotal = descTotalTotal + descTotal;
                descuento = 0.00;
                descTotal = 0.00;
                montoCIva = 0.00;
                renglon = 460;
                cb.endText();
                documento.newPage();
                documento.setPageSize(PageSize.A4.rotate());
                cb.beginText();

                contadorPaginas++;
                cb.setFontAndSize(bf, 12);
                //cb.setTextMatrix(250,820);
                //cb.showText("Subdiario de IVA Ventas");
                cb.setFontAndSize(bf, 10);
                cb.setTextMatrix(20, 480);
                cb.showText("Periodo " + periodo);
                //cb.setTextMatrix(750,550);
                //cb.showText("Hoja "+contadorPaginas+" de "+totalPaginas);

                //aca empieza la iteracion

                //encabezados
                bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                cb.setFontAndSize(bf, 8);
                cb.setTextMatrix(20, renglon);
                cb.showText("Cbte");
                cb.setTextMatrix(50, renglon);
                cb.showText("Fecha");
                cb.setTextMatrix(90, renglon);
                cb.showText("Nro Factura");
                cb.setTextMatrix(150, renglon);
                cb.showText("Cliente");
                cb.setTextMatrix(500, renglon);
                //tot=saldo.getCantidad() * saldo.getPrecioUnitario();
                cb.showText("Cond");
                cb.setTextMatrix(540, renglon);
                cb.showText("C.U.I.T.");
                cb.setTextMatrix(610, renglon);
                cb.showText("Neto");
                cb.setTextMatrix(660, renglon);
                cb.showText("I.V.A.");
                cb.setTextMatrix(700, renglon);
                cb.showText("Imp. Int.");
                cb.setTextMatrix(760, renglon);
                cb.showText("Total");
                renglon = renglon - 20;

                //fin encabezados
                bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                cb.setFontAndSize(bf, 6);
            }
        }

        bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.setFontAndSize(bf, 7);
        cb.setTextMatrix(540, renglon);
        cb.showText("Subtotal:");
        cb.setTextMatrix(600, renglon);
        cb.showText(Numeros.ConvetirNumeroDosDigitos(montoCIva));
        cb.setTextMatrix(650, renglon);
        cb.showText(Numeros.ConvetirNumeroDosDigitos(descuento));
        cb.setTextMatrix(710, renglon);
        cb.showText("0.00");
        cb.setTextMatrix(750, renglon);
        cb.showText(Numeros.ConvetirNumeroDosDigitos(descTotal));
        renglon = renglon - 10;

        montoCIvaTotal = montoCIvaTotal + montoCIva;
        descuentoTotal = descuentoTotal + descuento;

        descTotalTotal = descTotalTotal + descTotal;
        cb.setTextMatrix(540, renglon);
        cb.showText("Total:");
        cb.setTextMatrix(600, renglon);
        cb.showText(Numeros.ConvetirNumeroDosDigitos(montoCIvaTotal));
        cb.setTextMatrix(650, renglon);
        cb.showText(Numeros.ConvetirNumeroDosDigitos(descuentoTotal));
        cb.setTextMatrix(710, renglon);
        cb.showText("0.00");
        cb.setTextMatrix(750, renglon);
        cb.showText(Numeros.ConvetirNumeroDosDigitos(descTotalTotal));

        descuento = 0.00;
        descTotal = 0.00;
        montoCIva = 0.00;

        cb.endText();
        documento.close();

        File f = new File(arch);
        if (f.exists()) {

            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + arch);
        }
        int confirmacion = 0;
        /*
        if(doc.getArchivo().isEmpty()){
                
        }else{
        confirmacion=JOptionPane.showConfirmDialog(null, "DESEA NOTIFICAR POR MAIL?");
        if(confirmacion==0){
        //JOptionPane.showMessageDialog(null,"acepto");
                
        }
        }
            */
        System.out.println("eligio " + confirmacion);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(pdfsJavaGenerador.class.getName()).log(Level.SEVERE, null, ex);

    } catch (DocumentException ex) {
        Logger.getLogger(pdfsJavaGenerador.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(pdfsJavaGenerador.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(pdfsJavaGenerador.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:fattura.Fattura.java

public void setFattura(String cliente, String data, AtomicInteger numerofattura, PdfStamper s)
        throws SQLException, DocumentException, FileNotFoundException, IOException { //Ho messo che il numero della fattura va passato come parametro, voglio capire se si pu fare altrimenti (con un contatore)

    try {/*from www.j  av a 2s  . c  o  m*/

        s.getAcroFields().setField("Num", numerofattura.toString()); // sistemare
        s.getAcroFields().setField("Data", data);
        s.getAcroFields().setField("Nome", cliente);
        PdfContentByte content = s.getUnderContent(1);//1 for the first page
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
        content.beginText();
        content.setFontAndSize(bf, 7);
        inserisciDatiMaglie(cliente, data, s);
        inserisciDatiBorse(cliente, data, s);
        inserisciDatiPanta(cliente, data, s);
        inserisciDatiGiubb(cliente, data, s);
        inserisciDatiFelpe(cliente, data, s);
        inserisciDatiPubb(cliente, data, s);
        setImporti(s);
        content.endText();
        s.close();

    } catch (IOException | DocumentException e) {

    }
}

From source file:fattura.Fattura.java

public void inserisciDatiMaglie(String cliente, String data, PdfStamper s)
        throws SQLException, IOException, DocumentException {
    ArrayMaglia arraymaglia = new ArrayMaglia();
    arraymaglia.ArrayIDmaglia(cliente, data);
    float importo;

    PdfContentByte content = s.getUnderContent(1);//1 for the first page
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    content.setFontAndSize(bf, 7);

    for (int j = 0; j < arraymaglia.IDmaglie.length; j++) {
        arraymaglia.accessoMaglie(j);/*  w  w w .  j av a 2 s .  c o  m*/
        importo = arraymaglia.importoMaglia(j);
        String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo,  solo un appoggio
        importi.add(importo); //salva l'importo maglia nella prima posizione array i cui elementi poi andranno sommati per calcolare il totale

        for (int z = 0; z < arraymaglia.riga.length; z++) {
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, arraymaglia.riga[z] + "   ", 95 + x, 538 - y, 0);
            x += 97; //sposta la coordinata y ad ogni stampa
        }

        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Maglia", 95 + x, 538 - y, 0);
        x += 96;
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0);

        x = 0;
        y += 20;
    }

}

From source file:fattura.Fattura.java

public void inserisciDatiBorse(String cliente, String data, PdfStamper s)
        throws SQLException, IOException, DocumentException {
    ArrayBorsa arrayborsa = new ArrayBorsa();
    arrayborsa.ArrayIDborsa(cliente, data);
    float importo;

    PdfContentByte content = s.getUnderContent(1);//1 for the first page
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    content.setFontAndSize(bf, 7);

    for (int j = 0; j < arrayborsa.IDborse.length; j++) {
        arrayborsa.accessoBorse(j);/*from w w  w  .  j a  v a2s. com*/
        importo = arrayborsa.importoBorsa(j);
        String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo,  solo un appoggio
        importi.add(importo);
        for (int z = 0; z < arrayborsa.riga.length; z++) {
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, arrayborsa.riga[z] + "   ", 95 + x, 538 - y, 0);
            x += 97; //sposta la coordinata y ad ogni stampa

        }
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Borsa", 95 + x, 538 - y, 0);
        x += 97;
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0);
        x = 0;
        y += 20;
    }
    //MI calcolar il prezzo totale man mano che calcolo i preventivi lo agggiungo!

}

From source file:fattura.Fattura.java

public void inserisciDatiPanta(String cliente, String data, PdfStamper s)
        throws SQLException, IOException, DocumentException {
    ArrayPantalone arraypanta = new ArrayPantalone();
    arraypanta.ArrayIDpantalone(cliente, data);
    float importo = (float) 0.00;

    PdfContentByte content = s.getUnderContent(1);//1 for the first page
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    content.setFontAndSize(bf, 7);

    for (int j = 0; j < arraypanta.IDpantaloni.length; j++) {
        arraypanta.accessoPantaloni(j);// w w w .j  a va  2  s  .c  o m
        importo = arraypanta.importoPanta(j);
        String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo,  solo un appoggio
        importi.add(importo);
        for (int z = 0; z < arraypanta.riga.length; z++) {
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, arraypanta.riga[z] + "   ", 95 + x, 538 - y, 0);
            x += 97; //sposta la coordinata y ad ogni stampa

        }
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Pantalone", 95 + x, 538 - y, 0);
        x += 97;
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0);
        x = 0;
        y += 20;
    }
}

From source file:fattura.Fattura.java

public void inserisciDatiGiubb(String cliente, String data, PdfStamper s)
        throws SQLException, IOException, DocumentException {
    ArrayGiubbotto arraygiubb = new ArrayGiubbotto();
    arraygiubb.ArrayIDgiubbotto(cliente, data);
    float importo;

    PdfContentByte content = s.getUnderContent(1);//1 for the first page
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    content.setFontAndSize(bf, 7);

    for (int j = 0; j < arraygiubb.IDgiubbotti.length; j++) {
        arraygiubb.accessoGiubbotti(j);//from w w  w.j  a va  2  s.c om
        importo = arraygiubb.importoGiubbotto(j);
        String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo,  solo un appoggio
        importi.add(importo);
        for (int z = 0; z < arraygiubb.riga.length; z++) {
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, arraygiubb.riga[z] + "   ", 95 + x, 538 - y, 0);
            x += 97; //sposta la coordinata y ad ogni stampa

        }
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Giubbotto", 95 + x, 538 - y, 0);
        x += 97;
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0);
        x = 0;
        y += 20;
    }

}

From source file:fattura.Fattura.java

public void inserisciDatiFelpe(String cliente, String data, PdfStamper s)
        throws SQLException, IOException, DocumentException {
    ArrayFelpa arrayfelpa = new ArrayFelpa();
    arrayfelpa.ArrayIDfelpa(cliente, data);
    float importo;

    PdfContentByte content = s.getUnderContent(1);//1 for the first page
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    content.setFontAndSize(bf, 7);

    for (int j = 0; j < arrayfelpa.IDfelpe.length; j++) {
        arrayfelpa.accessoFelpe(j);/*w  ww  .  jav a2s . c o  m*/
        importo = arrayfelpa.importoFelpa(j);
        String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo,  solo un appoggio
        importi.add(importo);
        for (int z = 0; z < arrayfelpa.riga.length; z++) {
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, arrayfelpa.riga[z] + "   ", 95 + x, 538 - y, 0);
            x += 97; //sposta la coordinata y ad ogni stampa

        }
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Felpa", 95 + x, 538 - y, 0);
        x += 97;
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0);
        x = 0;
        y += 20;
    }
    //MI calcolar il prezzo totale man mano che calcolo i preventivi lo agggiungo!

}

From source file:fattura.Fattura.java

public void inserisciDatiPubb(String cliente, String data, PdfStamper s)
        throws SQLException, IOException, DocumentException {
    ArrayPubblicita arraypubb = new ArrayPubblicita();
    arraypubb.ArrayIDpubb(cliente, data);
    float importo;

    PdfContentByte content = s.getUnderContent(1);//1 for the first page
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    content.setFontAndSize(bf, 7);

    for (int j = 0; j < arraypubb.IDpubb.length; j++) {
        arraypubb.accessoPubb(j);/*from  www  . j a  v a2s  .c  o  m*/
        importo = arraypubb.importoPubblicita(j);
        String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo,  solo un appoggio
        importi.add(importo); //salva l'importo maglia nella prima posizione array i cui elementi poi andranno sommati per calcolare il totale

        for (int z = 0; z < arraypubb.riga.length; z++) {
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, arraypubb.riga[z] + "   ", 95 + x, 538 - y, 0);
            x += 97; //sposta la coordinata y ad ogni stampa
        }

        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Mat. Pubb.", 95 + x, 538 - y, 0);
        x += 101;
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0);

        x = 0;
        y += 20;
    }

}

From source file:fll.util.SimpleFooterHandler.java

License:Open Source License

@Override
public void onEndPage(final PdfWriter writer, final Document document) {
    final PdfContentByte cb = writer.getDirectContent();
    cb.saveState();/*  w  w  w  .j ava2s.com*/

    // compose the footer
    final String text = "Page " + writer.getPageNumber() + " of ";
    final float textSize = _headerFooterFont.getWidthPoint(text, 12);
    final float textBase = document.bottom() - 20;
    cb.beginText();
    cb.setFontAndSize(_headerFooterFont, 12);

    final float adjust = _headerFooterFont.getWidthPoint("0", 12);
    cb.setTextMatrix(document.right() - textSize - adjust, textBase);
    cb.showText(text);
    cb.endText();
    cb.addTemplate(_tpl, document.right() - adjust, textBase);

    cb.restoreState();
}

From source file:gravabncertificado.GerandoArquivoCarimbado_1.java

public static void GerandoArquivoCarimbadoPDF(String caminhoarquivo, String BN) throws InvalidPdfException {
    //Copiando arquivo informado.
    try {//  ww w .j a  v a2  s.co m

        // Adicionado parametro para nao retornar erro quando o documento for protegido.
        PdfReader.unethicalreading = true;
        //Cria o reader para o primeiro PDF

        PdfReader reader = new PdfReader(caminhoarquivo);

        // n recebe o numero total de paginas
        int n = reader.getNumberOfPages();

        //Tamanho da primeira Pagina
        ;

        //Cria Segundo PDF

        Document document = new Document(PageSize.A4, 36, 36, 36, 36);

        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-C.pdf"));

        document.open();

        // Adiciona conteudo ao PDF Carimbado.
        PdfContentByte cb = writer.getDirectContent();
        int i = 0;
        int p = 0;
        String caminhodestino = (caminhoarquivo.substring(0, caminhoarquivo.length() - BN.length()));

        // DESABILITADO PORQUE O MOVER NAO ESTAVA FUNCIONANDO.
        File destinooriginal = new File(caminhodestino + "ORIGINAL\\");
        if (!destinooriginal.exists()) {
            destinooriginal.mkdir();
        }

        caminhodestino = (caminhodestino + "ORIGINAL\\" + BN);

        //TESTANDO NOVA FORMA DE COPIAR

        File origem = new File(caminhoarquivo);
        File destino = new File(caminhodestino);

        FileInputStream fis = new FileInputStream(origem);
        FileOutputStream fos = new FileOutputStream(destino);

        FileChannel inChannel = fis.getChannel();
        FileChannel outChannel = fos.getChannel();

        long transferFrom = outChannel.transferFrom(inChannel, 0, inChannel.size());

        fis.close();
        fos.close();
        inChannel.close();
        outChannel.close();

        // Thread.sleep(10);

        BN = BN.substring(0, BN.length() - 4);

        while (i < n) {
            document.newPage();
            p++;
            i++;

            PdfContentByte under = writer.getDirectContentUnder();
            PdfImportedPage page1 = writer.getImportedPage(reader, i);
            cb.addTemplate(page1, 0, i * 0.2f);

            // Page 1: a rectangle
            /* RETANGULO DESATIVADO
            drawRectangle(under, 100, 50);
            under.setRGBColorFill(255, 220, 220);
            under.rectangle(width /50, 5, 118, 40);
            under.fill();
            */

            //CARIMBO DA BN

            BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            cb.beginText();
            cb.setFontAndSize(bf, 14);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 44, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 32, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 22, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " NR", width / 6, 28, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " " + BN, width / 6, 16, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 12, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 14, 0);
            cb.endText();

        }

        document.close();
        writer.close();
        reader.close();
        origem.delete();

        /* PdfContentByte under = writer.getDirectContentUnder();
                 
         // Page 1: a rectangle
             drawRectangle(under, 20, 20);
             under.setRGBColorFill(0xFF, 0xD7, 0x00);
             under.rectangle(5, 5, 15, 15);
             under.fill(); */
        //document.newPage();

        //COPIANDO ARQUIVO CARIMBADO

        /* DESABILITADO PORQUE NAO ESTAVA FUNCIONANDO.
        boolean bool;
                
         //caminhoarquivo = caminhoarquivo.replace("\\", "\\\\");
         //caminhodestino = caminhodestino.replace("\\", "\\\\");
                    
        File origem = new File(caminhoarquivo);
        File destino = new File(caminhodestino);
                
                    
        bool = origem.renameTo(destino);
        System.out.println(origem);
        System.out.println(caminhodestino);
        */

    } catch (IOException | DocumentException ex) {
    }

}