Example usage for com.itextpdf.text.pdf PdfReader getFileLength

List of usage examples for com.itextpdf.text.pdf PdfReader getFileLength

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfReader getFileLength.

Prototype

public long getFileLength() 

Source Link

Document

Getter for property fileLength.

Usage

From source file:es.jscan.Pantallas.PantallaPrincipal.java

License:Apache License

private void crearXmlLote(String lote) {
    Calendar cal = Calendar.getInstance();
    String anio = String.valueOf(cal.get(Calendar.YEAR));
    String mes = String.valueOf((cal.get(Calendar.MONTH) + 1)).length() == 1
            ? "0" + String.valueOf((cal.get(Calendar.MONTH) + 1))
            : String.valueOf((cal.get(Calendar.MONTH) + 1));
    String dia = String.valueOf(cal.get(Calendar.DAY_OF_MONTH)).length() == 1
            ? "0" + String.valueOf(cal.get(Calendar.DAY_OF_MONTH))
            : String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
    String hora = String.valueOf(cal.get(Calendar.HOUR_OF_DAY)).length() == 1
            ? "0" + String.valueOf(cal.get(Calendar.HOUR_OF_DAY))
            : String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
    String minuto = String.valueOf(cal.get(Calendar.MINUTE)).length() == 1
            ? "0" + String.valueOf(cal.get(Calendar.MINUTE))
            : String.valueOf(cal.get(Calendar.MINUTE));
    String segundo = String.valueOf(cal.get(Calendar.SECOND)).length() == 1
            ? "0" + String.valueOf(cal.get(Calendar.SECOND))
            : String.valueOf(cal.get(Calendar.SECOND));

    String dirorigen = rutadigita + separador + "lotes" + separador + lote + separador;
    File dir = new File(dirorigen);

    FilenameFilter filtropdf = new FiltroPdf();
    String ficheros[] = dir.list(filtropdf);

    String ficheroxml = rutadigita + separador + "lotes" + separador + lote + separador + lote + ".xml";

    XmlLote Lote = new XmlLote();
    XmlInfo Info = new XmlInfo();

    String numpaginas = "";
    String tam = "";
    String proceso = "";
    String usuarioldap = "";
    String ip = "";
    String provincia = "";
    String fechadigita = "";
    String fechacreacion = "";
    String expediente = "";
    String cb = "";
    String notificarinstructor = "";
    String tipodocumento = "";
    String fechanotificacion = "";
    String actualizarfase = "";
    String ubicacionfisica = "";

    for (int i = 0; i < ficheros.length; i++) {
        String fich = ficheros[i].toString();
        try {//from   ww  w .  ja  v a  2  s  .  c o m
            PdfReader reader = new PdfReader(dirorigen + fich);
            proceso = (reader.getInfo().get("proceso") == null ? "" : reader.getInfo().get("proceso"));
            usuarioldap = (reader.getInfo().get("usuarioldap") == null ? ""
                    : reader.getInfo().get("usuarioldap"));
            ip = (reader.getInfo().get("IP") == null ? "" : reader.getInfo().get("IP"));
            provincia = (reader.getInfo().get("provincia") == null ? "" : reader.getInfo().get("provincia"));
            fechadigita = (reader.getInfo().get("fechadigita") == null ? ""
                    : reader.getInfo().get("fechadigita"));
            fechacreacion = (reader.getInfo().get("fechacreacion") == null ? ""
                    : reader.getInfo().get("fechacreacion"));
            numpaginas = "" + reader.getNumberOfPages();
            tam = "" + NumberFormat.getInstance().format(reader.getFileLength());
            expediente = (reader.getInfo().get("Expediente") == null ? "" : reader.getInfo().get("Expediente"));
            cb = (reader.getInfo().get("codigobarras") == null ? "" : reader.getInfo().get("codigobarras"));
            notificarinstructor = (reader.getInfo().get("notificarinstructor") == null ? ""
                    : reader.getInfo().get("notificarinstructor"));
            tipodocumento = (reader.getInfo().get("tipodocumento") == null ? ""
                    : reader.getInfo().get("tipodocumento"));
            fechanotificacion = (reader.getInfo().get("fechanotificacion") == null ? ""
                    : reader.getInfo().get("fechanotificacion"));
            actualizarfase = (reader.getInfo().get("actualizarfase") == null ? ""
                    : reader.getInfo().get("actualizarfase"));
            ubicacionfisica = (reader.getInfo().get("ubicacionfisica") == null ? ""
                    : reader.getInfo().get("ubicacionfisica"));

        } catch (IOException ex) {
            Utilidades.escribeLog(
                    "Error -crearXmlLote- al leer el PDF " + dirorigen + fich + "  - Error " + ex.getMessage());
        }

        XmlDocumento doc = new XmlDocumento();
        doc.setExpediente(expediente);
        doc.setFichero(fich);
        doc.setNumPaginas(numpaginas);
        doc.setTam(tam);
        doc.setCb(cb);
        doc.setNotificarinstructor(notificarinstructor);
        doc.setTipodocumento(tipodocumento);
        doc.setFechanotificacion(fechanotificacion);
        doc.setActualizarfase(actualizarfase);
        doc.setUbicacionfisica(ubicacionfisica);
        Lote.add(doc);
    }

    Info.setFechacreacion(fechacreacion);
    Info.setFechadigita(fechadigita);
    Info.setFechaenvio(dia + "/" + mes + "/" + anio + " " + hora + ":" + minuto + ":" + segundo);
    Info.setIp(ip);
    Info.setNumdocumentos("" + ficheros.length);
    Info.setProceso(proceso);
    Info.setProvincia(provincia);
    Info.setUsuarioldap(usuarioldap);

    Lote.setInfo(Info);

    XStream xstream = new XStream();
    xstream.alias("Lote", XmlLote.class);
    xstream.alias("Info", XmlInfo.class);
    xstream.alias("Documento", XmlDocumento.class);

    try {
        xstream.toXML(Lote, new FileOutputStream(ficheroxml));
    } catch (FileNotFoundException ex) {
        Utilidades.escribeLog(
                "Error al escribir el fichero -crearXmlLote- " + ficheroxml + " - Error: " + ex.getMessage());
    }
}