Example usage for com.itextpdf.text.pdf PdfName ROTATE

List of usage examples for com.itextpdf.text.pdf PdfName ROTATE

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfName ROTATE.

Prototype

PdfName ROTATE

To view the source code for com.itextpdf.text.pdf PdfName ROTATE.

Click Source Link

Document

A name

Usage

From source file:Separator.java

License:Apache License

public static void crop(String inFileName, String outFileName, int split, boolean vert) throws Exception {

    PdfReader reader = new PdfReader(new File(inFileName).getAbsolutePath());
    String PDFName = outFileName.substring(outFileName.lastIndexOf("Folder\\") + 7,
            outFileName.indexOf(".pdf"));
    File fn = new File(scanFolder + PDFName + "\\" + PDFName + "_split_" + split + ".pdf");
    fn.getParentFile().mkdirs();/*from   ww w. j  av  a2  s.  c o  m*/

    int count = reader.getNumberOfPages();
    Document doc = new Document();
    PdfCopy copy = new PdfCopy(doc, new FileOutputStream(fn.getAbsolutePath()));
    doc.open();
    if (vert) {
        for (int i = 1; i <= count; i++) {
            reader.getPageN(i).put(PdfName.CROPBOX, new PdfRectangle(PageSize.LETTER));
            copy.addPage(copy.getImportedPage(reader, i));
        }
    } else {
        if (!doubSided) {
            for (int j = 1; j <= count; j++) {
                reader.getPageN(j).put(PdfName.CROPBOX, new PdfRectangle((new Rectangle(0, 180, 792, 792))));
                PdfDictionary pageDict;
                int rot = reader.getPageRotation(j);
                pageDict = reader.getPageN(j);
                pageDict.put(PdfName.ROTATE, new PdfNumber(rot + 90));
                copy.addPage(copy.getImportedPage(reader, j));
            }
        } else {
            for (int j = 1; j <= count; j++) {
                reader.getPageN(j).put(PdfName.CROPBOX, new PdfRectangle(new Rectangle(0, 180, 792, 792)));
                PdfDictionary pageDict;
                pageDict = reader.getPageN(j);
                if (j % 2 == 0) { // even
                    pageDict.put(PdfName.ROTATE, new PdfNumber(270));
                } else { // odd
                    pageDict.put(PdfName.ROTATE, new PdfNumber(90));
                }
                copy.addPage(copy.getImportedPage(reader, j));
            }
        }
    }
    doc.close();
}

From source file:Excel.pdfsJavaGenerador.java

public void run() {
    Document documento = new Document();
    documento.setPageSize(PageSize.A4.rotate());
    int i = 1;//  w  ww.  j av a  2s  .  com
    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:org.sejda.impl.itext5.component.PdfRotator.java

License:Open Source License

/**
 * apply the rotation to the given page if necessary
 * /*from w w  w.j a  v  a 2s  . c o m*/
 * @param pageNmber
 */
private void apply(int pageNmber) {
    if (rotation.accept(pageNmber)) {
        int pageRotation = reader.getPageRotation(pageNmber);
        PdfDictionary dictionary = reader.getPageN(pageNmber);
        dictionary.put(PdfName.ROTATE,
                new PdfNumber(rotation.getRotation().addRotation(getRotation(pageRotation)).getDegrees()));
    }
}

From source file:oscar.dms.IncomingDocUtil.java

License:Open Source License

public static void rotatePage(String queueId, String myPdfDir, String myPdfName, String MyPdfPageNumber,
        int degrees) throws Exception {
    long lastModified;
    String filePathName, tempFilePathName;
    int rot;/*from w w w . j ava  2  s. c om*/
    int rotatedegrees;

    tempFilePathName = getIncomingDocumentFilePath(queueId, myPdfDir) + File.separator + "T" + myPdfName;
    filePathName = getIncomingDocumentFilePathName(queueId, myPdfDir, myPdfName);

    File f = new File(filePathName);
    lastModified = f.lastModified();

    PdfReader reader = null;
    PdfStamper stp = null;

    try {
        reader = new PdfReader(filePathName);
        rot = reader.getPageRotation(Integer.parseInt(MyPdfPageNumber));
        rotatedegrees = rot + degrees;
        rotatedegrees = rotatedegrees % 360;

        reader.getPageN(Integer.parseInt(MyPdfPageNumber)).put(PdfName.ROTATE, new PdfNumber(rotatedegrees));
        stp = new PdfStamper(reader, new FileOutputStream(tempFilePathName));

    } catch (Exception e) {
        throw (e);
    } finally {
        try {
            if (stp != null) {
                stp.close();
            }

            if (reader != null) {
                reader.close();
            }
        } catch (Exception e) {
            throw (e);
        }
    }

    boolean success = f.delete();

    if (success) {
        File f1 = new File(tempFilePathName);
        f1.setLastModified(lastModified);
        success = f1.renameTo(new File(filePathName));
        if (!success) {
            throw new Exception("Error in renaming file from:" + tempFilePathName + " to " + filePathName);
        }
    } else {
        throw new Exception("Error in deleting file:" + filePathName);
    }
}

From source file:oscar.dms.IncomingDocUtil.java

License:Open Source License

public static void rotateAlPages(String queueId, String myPdfDir, String myPdfName, int degrees)
        throws Exception {
    long lastModified;
    String filePathName, tempFilePathName;
    int rot;//from   w  w w  .  j a v a  2  s .c o m
    int rotatedegrees;

    tempFilePathName = getIncomingDocumentFilePath(queueId, myPdfDir) + File.separator + "T" + myPdfName;
    filePathName = getIncomingDocumentFilePathName(queueId, myPdfDir, myPdfName);

    File f = new File(filePathName);
    lastModified = f.lastModified();

    PdfReader reader = null;
    PdfStamper stp = null;

    try {
        reader = new PdfReader(filePathName);

        for (int p = 1; p <= reader.getNumberOfPages(); ++p) {
            rot = reader.getPageRotation(p);
            rotatedegrees = rot + degrees;
            rotatedegrees = rotatedegrees % 360;

            reader.getPageN(p).put(PdfName.ROTATE, new PdfNumber(rotatedegrees));
        }
        stp = new PdfStamper(reader, new FileOutputStream(tempFilePathName));

    } catch (Exception e) {
        throw (e);
    } finally {
        try {
            if (stp != null) {
                stp.close();
            }

            if (reader != null) {
                reader.close();
            }
        } catch (Exception e) {
            throw (e);
        }
    }

    boolean success = f.delete();

    if (success) {
        File f1 = new File(tempFilePathName);
        f1.setLastModified(lastModified);
        success = f1.renameTo(new File(filePathName));
        if (!success) {
            throw new Exception("Error in renaming file from:" + tempFilePathName + "to " + filePathName);
        }
    } else {
        throw new Exception("Error in deleting file:" + filePathName);
    }
}