package asignacionServlet;

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import m05bClasses.m05bCamposInformes;
import m05bClasses.m05bComun;
import m05bClasses.m05bConstantes;
import m05bClasses.m05bConstantesInformes;
import m05bClasses.m05bFileLog;

import org.apache.fop.apps.Driver;
import org.xml.sax.InputSource;

import weblogic.utils.encoders.BASE64Encoder;


public class m05bImpEntDevServlet extends javax.servlet.http.HttpServlet
{
   public static final String FO_REQUEST_PARAM = "fo";
   m05bFileLog miLog = new m05bFileLog();
   public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
   {
 	   try{
 		   doGet(request, response);
 	   }catch (Exception e){
 		  miLog.addTraza(e);
 	   }
   }

   public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException
   {
      performTask(request, response);
   }

   public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ServletException
   {
	  String fsolicitud="", nsolicitud="", desde="", hasta="", horadesde="", horahasta="", 
	  			comentarios="", kmsalida="", kmllegada="", fdevolucion="", horadevolucion="", 
  				nombre="", departamento="", firma="";

	  String vehiculo[];

      try
      {
    	 HttpSession session = request.getSession(true);
      	 String persona = (String) session.getAttribute("persona");
		 m05bFileLog miLog = new m05bFileLog();
      	 miLog.addTraza(persona, "Imp Ent Dev", "INICIO", m05bConstantes.LOG_NIVEL_BAJO);

		 m05bComun miComun = new m05bComun();
      	 // Obtención de información de BD
 	 	 // Vehículo
      	 	 
      	 String matricula=request.getParameter("Matricula");
      	 if (!(matricula.equals(""))) {
	      	 miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "MATRICULA-1: " + matricula, m05bConstantes.LOG_NIVEL_BAJO);
	      	 fsolicitud=(String) session.getAttribute("PDFFSolicitud");
	      	 nsolicitud=(String) session.getAttribute("GastosAsig");
	      	 if (nsolicitud != null) {
	      	 	nsolicitud=miComun.formatearStrMiles(nsolicitud);
	      	 }
	      	 desde=(String) session.getAttribute("GastosDesde");
	      	 hasta=(String) session.getAttribute("GastosHasta");
	      	 horadesde=(String) session.getAttribute("GastosHDesde");
	      	 horahasta=(String) session.getAttribute("GastosHHasta");
	      	 comentarios=(String) session.getAttribute("PDFMotivo");
	      	 if (comentarios==null)
	      	 	 comentarios="";
	      	 miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "COMENTARIOS: " , m05bConstantes.LOG_NIVEL_BAJO);
	      	 kmsalida=miComun.formatearStrMiles((String) session.getAttribute("PDFKmSalida"));
	      	 kmllegada=miComun.formatearStrMiles((String) session.getAttribute("PDFKmLLegada"));
	      	 fdevolucion=(String) session.getAttribute("PDFFDevolucion");
	      	 if ((fdevolucion==null) || (fdevolucion.equals("")))
	      	 	 kmllegada="";
	      	 horadevolucion=(String) session.getAttribute("PDFHDevolucion");

	     	 m05bCamposInformes miVehiculo = new m05bCamposInformes();
	      	 vehiculo = miVehiculo.getDatosVehiculo(matricula);
	      	 //String tarjeta = miVehiculo.getTarjeta(matricula);
	      	 // Titular
	      	 /* String cargo = (String) session.getAttribute("PDFCargo");  // Se pone en la sesion en JSP Asignaciones
	      	 String ecargo = miVehiculo.getCargoEusk((String) session.getAttribute("PDFCodCargo")); // Se pone en la sesion en JSP Asignaciones
	      	 */
	      	 nombre = (String) session.getAttribute("PDFNombre");  // Se pone en la sesion en JSP Asignaciones
	      	 // Departamento
	      	 departamento = (String) session.getAttribute("PDFDpto");
	      	 // String edepartamento = miVehiculo.getDepartEusk((String) session.getAttribute("PDFCodDpto"));
	      	 // Firma
	      	 firma = miVehiculo.getFirma(m05bConstantesInformes.DET7_C_ACTA);
      	 }

      	 miLog.addTraza("", "", "FIN IF", m05bConstantes.LOG_NIVEL_BAJO);
	     String xlnetsini = miComun.leerPropiedad("xlnets");
         //String urlprin = xlnetsini.substring(0, xlnetsini.indexOf("/", 8));

         //String foParam = request.getParameter(FO_REQUEST_PARAM);
         String sFoFileDir = "/datos/m05b/tmp/";
         File foFileDir = new File(sFoFileDir);
         File tmpFoFile = File.createTempFile("m05b", "Fo", foFileDir);


         FileOutputStream tmpFoFileStream = new FileOutputStream(tmpFoFile);

         String sLinea;

         sLinea = "<?xml version=\"1.0\" encoding=\"windows-1252\"?>\n";
         tmpFoFileStream.write(sLinea.getBytes());
         
         sLinea = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">\n";
         tmpFoFileStream.write(sLinea.getBytes());
		 // LAYOUT DEL LISTADO 
	         sLinea = "<fo:layout-master-set>\n";
	         tmpFoFileStream.write(sLinea.getBytes());
		         sLinea = "	<fo:simple-page-master master-name=\"general\" page-height=\"29.5cm\" page-width=\"21cm\" margin-top=\"0.5cm\" margin-bottom=\"3cm\" margin-left=\"2cm\" margin-right=\"2.5cm\">\n";
			     tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-before extent=\"0cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-body margin-bottom=\"0cm\" margin-top=\"0cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-after extent=\"0cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-start extent=\"0cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-end extent=\"0cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
		         sLinea = "	</fo:simple-page-master>\n";
		         tmpFoFileStream.write(sLinea.getBytes());
	         sLinea = "</fo:layout-master-set>\n";
	         tmpFoFileStream.write(sLinea.getBytes());
		 // PAGE-SEQUENCE DEL LISTADO 
	         sLinea = "<fo:page-sequence master-reference=\"general\">\n";
	         tmpFoFileStream.write(sLinea.getBytes());
		         sLinea = "	<fo:flow flow-name=\"xsl-region-body\">\n";
		         tmpFoFileStream.write(sLinea.getBytes());

		         // --------------    CABECERA DEL LISTADO    --------------
                        //Cabecera 1
		            sLinea = "		<fo:block-container position=\"absolute\" top=\"0cm\" left=\"3.4cm\" width=\"10.5cm\" height=\"1.7cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	//  Escudo
			            sLinea = "			<fo:external-graphic src=\"" + "/datos/m05b/file/images/fop/cabeceraHacFin.jpg\" height=\"1.7cm\" width=\"10.5cm\"/>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());


		            sLinea = "      <fo:block-container position=\"absolute\" top=\"2.8cm\" left=\"0.69cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"75mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"75mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"10pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Blanco1
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"4pt\" text-align=\"center\"  >\n " + m05bConstantesInformes.TIT_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Blanco2
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"4pt\">\n " + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Cuadro vacío
			            			sLinea = "	    <fo:table-cell >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"4pt\" text-align=\"center\" >\n " + m05bConstantesInformes.TIT_C_VEHICULO_ENTDEV  + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());


		            sLinea = "      <fo:block-container position=\"absolute\" top=\"3.4cm\" left=\"0.69cm\" width=\"15cm\" height=\"2.75cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"160mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"10pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Blanco1
			            			sLinea = "	    <fo:table-cell border-width=\"0.3mm\" border-style=\"solid\" >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
                  		            	// Título Castellano
			                                sLinea = "			<fo:block font-family=\"Helvetica\" font-weight=\"bold\" font-size=\"10pt\" text-align=\"center\"  >\n "  ;
			                                tmpFoFileStream.write(sLinea.getBytes());
                   			              sLinea = "	    	</fo:block>\n";
		                                      tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
  			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());

		            
      	         // --------------    DETALLE DEL LISTADO    --------------

	            	// Datos del Solicitante Cabecera
		            sLinea = "      <fo:block-container position=\"absolute\" top=\"3.7cm\" left=\"0.69cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"55mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"105mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Blanco1
			            			sLinea = "	    <fo:table-cell background-color=\"rgb(192,192,192)\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"3pt\" text-align=\"left\"  >\n " + m05bConstantesInformes.CAB1_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
					                        sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " + m05bConstantesInformes.CAB1_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Blanco2
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"4pt\">\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());


		            sLinea = "      <fo:block-container position=\"absolute\" top=\"4.8cm\" left=\"0.75cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"38mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"37mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"40mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"35mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Fecha de solicitud
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"  text-align=\"left\"  >\n " + m05bConstantesInformes.DET11_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " + m05bConstantesInformes.DET11_C_VEHICULO_ENTDEV+ "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda Fecha de 
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\" text-align=\"center\" >\n " + fsolicitud + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
								//  Columna en blanco
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"   >\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Numero de Solicitud
			            			sLinea = "	    <fo:table-cell >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block text-align=\"left\" font-weight=\"bold\">\n " +  m05bConstantesInformes.DET12_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\" >\n " +  m05bConstantesInformes.DET12_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		      //  Celda Numero de Solicitud
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\" text-align=\"center\" >\n " + nsolicitud + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());

		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());

		            sLinea = "      <fo:block-container position=\"absolute\" top=\"5.8cm\" left=\"0.75cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"38mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"122mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Número de solicitud 
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"  text-align=\"left\"  >\n " +  m05bConstantesInformes.DET13_E_VEHICULO_ENTDEV  + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " +  m05bConstantesInformes.DET13_C_VEHICULO_ENTDEV  + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda Fecha de 
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"4pt\"  margin-left=\"4pt\" >\n <![CDATA[" + nombre + "]]></fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());

		            sLinea = "      <fo:block-container position=\"absolute\" top=\"6.8cm\" left=\"0.75cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"38mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"122mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Departamento
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"    >\n " +  m05bConstantesInformes.DET14_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " +  m05bConstantesInformes.DET14_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());

			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda Fecha de 
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"4pt\" margin-left=\"4pt\" >\n <![CDATA[" + departamento + "]]></fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());

		            sLinea = "      <fo:block-container position=\"absolute\" top=\"7.8cm\" left=\"0.75cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"38mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"122mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Motivo de la solicitud
			            			sLinea = "	    <fo:table-cell height=\"2cm\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"    >\n " +  m05bConstantesInformes.DET15_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " +  m05bConstantesInformes.DET15_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda Comentarios
			            			sLinea = "	    <fo:table-cell height=\"2cm\" border-style=\"solid\" border-width=\"0.05mm\" font-size=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"4pt\"  margin-left=\"4pt\" >\n <![CDATA[" + comentarios + "]]></fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());


		            sLinea = "      <fo:block-container position=\"absolute\" top=\"10.3cm\" left=\"0.75cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"38mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"37mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"40mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"35mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Fecha de inicio utilizacion
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"    >\n " +  m05bConstantesInformes.DET16_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " +  m05bConstantesInformes.DET16_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());

			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda Fecha de 
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\" text-align=\"center\" >\n " + desde +"</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
								//  Columna en blanco
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"   >\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Hora de inicio de utilización
			            			sLinea = "	    <fo:table-cell >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block  font-weight=\"bold\">\n " +  m05bConstantesInformes.DET17_E_VEHICULO_ENTDEV  + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\" >\n " +  m05bConstantesInformes.DET17_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());

			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		      //  Hora de inicio
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\" text-align=\"center\" >\n " + horadesde +"</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());

		            sLinea = "      <fo:block-container position=\"absolute\" top=\"11.5cm\" left=\"0.75cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"38mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"37mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"40mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"35mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Fecha fin prevista
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"    >\n " +  m05bConstantesInformes.DET18_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " +  m05bConstantesInformes.DET18_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());

			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda Fecha fin prevista
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\" text-align=\"center\" >\n " + hasta + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";     
			            			tmpFoFileStream.write(sLinea.getBytes());
								//  Columna en blanco
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"   >\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			//  hora fin prevista
			            			sLinea = "	    <fo:table-cell >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block  font-weight=\"bold\">\n " +  m05bConstantesInformes.DET19_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\" >\n " +  m05bConstantesInformes.DET19_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		      //  Celda hora fin prevista
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\" text-align=\"center\" >\n " + horahasta + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());


	            	// Datos del Solicitante Cabecera
		            sLinea = "      <fo:block-container position=\"absolute\" top=\"12.7cm\" left=\"0.69cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"55mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"105mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  cabecera datos asignacion
			            			sLinea = "	    <fo:table-cell background-color=\"rgb(192,192,192)\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"3pt\" text-align=\"left\"  >\n " +  m05bConstantesInformes.CAB2_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " +  m05bConstantesInformes.CAB2_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Blanco2
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"4pt\">\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());

		            sLinea = "      <fo:block-container position=\"absolute\" top=\"13.9cm\" left=\"0.75cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"38mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"37mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"85mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			                sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Vehículo asignado.
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"    >\n " +  m05bConstantesInformes.DET21_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " +  m05bConstantesInformes.DET21_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());

			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Vehículo asignado.
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\" text-align=\"center\" >\n <![CDATA[" + matricula + "]]></fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
								//  Columna en blanco
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"   >\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());


		            sLinea = "      <fo:block-container position=\"absolute\" top=\"15.1cm\" left=\"0.75cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"38mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"37mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"85mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			                sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  kilómetros a la salida
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"    >\n " + m05bConstantesInformes.DET22_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " + m05bConstantesInformes.DET22_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Kilómetros a la salida
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\" text-align=\"center\" >\n " + kmsalida +"</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
								//  Columna en blanco
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"1pt\" text-align=\"left\"  >\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());

		            sLinea = "      <fo:block-container position=\"absolute\" top=\"16.1cm\" left=\"0.69cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"75mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"75mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Blanco1
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"51pt\"  margin-left=\"4pt\" >\n " + m05bConstantesInformes.DET4_E_VEHICULO_ENTDEV  + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\"  margin-left=\"4pt\" >\n " + m05bConstantesInformes.DET4_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Blanco2
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"4pt\">\n " + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Cuadro vacío
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"51pt\"  margin-left=\"4pt\" >\n " + m05bConstantesInformes.DET5_E_VEHICULO_ENTDEV  + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\"  margin-left=\"4pt\" >\n " + m05bConstantesInformes.DET5_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());


	            	// Datos del Solicitante Cabecera
		            sLinea = "      <fo:block-container position=\"absolute\" top=\"18.8cm\" left=\"0.69cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"55mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"105mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Blanco1
			            			sLinea = "	    <fo:table-cell background-color=\"rgb(192,192,192)\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"3pt\" text-align=\"left\"  >\n " + m05bConstantesInformes.CAB3_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " +  m05bConstantesInformes.CAB3_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Blanco2
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"4pt\">\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());

		            sLinea = "      <fo:block-container position=\"absolute\" top=\"20cm\" left=\"0.75cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"38mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"37mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"85mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			                sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Fecha de solicitud euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"    >\n " + m05bConstantesInformes.DET31_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " + m05bConstantesInformes.DET31_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());

			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda Fecha de 
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"10pt\" >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\" text-align=\"center\" >\n " + kmllegada+ "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
								//  Columna en blanco
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"   >\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());


		            sLinea = "      <fo:block-container position=\"absolute\" top=\"21.2cm\" left=\"0.75cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"38mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"37mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"40mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"35mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Fecha de solicitud euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"    >\n " + m05bConstantesInformes.DET32_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\"  >\n " + m05bConstantesInformes.DET32_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());

			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda Fecha de 
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\" text-align=\"center\" >\n " + fdevolucion + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
								//  Columna en blanco
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\"   >\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Numero de Solicitud Euskera
			            			sLinea = "	    <fo:table-cell >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block  font-weight=\"bold\">\n " + m05bConstantesInformes.DET33_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"0pt\" text-align=\"left\" >\n " + m05bConstantesInformes.DET33_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());

			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		      //  Celda Numero de Solicitud
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" font-size=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\" text-align=\"center\" >\n " + horadevolucion + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());

		            sLinea = "      <fo:block-container position=\"absolute\" top=\"22.2cm\" left=\"0.69cm\" width=\"15cm\" height=\"2.8cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"75mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"75mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Blanco1
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"51pt\"  margin-left=\"4pt\" >\n " + m05bConstantesInformes.DET4_E_VEHICULO_ENTDEV+ "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\"  margin-left=\"4pt\" >\n " + m05bConstantesInformes.DET4_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Blanco2
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"4pt\">\n " + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Cuadro vacío
			            			sLinea = "	    <fo:table-cell border-style=\"solid\" border-width=\"0.05mm\" >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"51pt\"  margin-left=\"4pt\" >\n " + m05bConstantesInformes.DET5_E_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block padding-top=\"3pt\"  margin-left=\"4pt\" >\n " + m05bConstantesInformes.DET5_C_VEHICULO_ENTDEV + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());




                        //PIE DE PAGINA Director de Recursos
		            sLinea = "      <fo:block-container position=\"absolute\" top=\"25.8cm\" left=\"0.69cm\" width=\"15cm\" height=\"2.75cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"160mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"10pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Letra Pequeña 1 Euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
                  		            	// Título Euskera
			                                sLinea = "			<fo:block font-family=\"Helvetica\" font-weight=\"bold\" font-size=\"6pt\">\n " + m05bConstantesInformes.PIE1_E_ACTA ;
			                                tmpFoFileStream.write(sLinea.getBytes());
                   			              sLinea = "	    	</fo:block>\n";
		                                      tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
  			            		tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Letra Pequeña 2 Euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
                  		            	// Título Euskera
			                                sLinea = "			<fo:block font-family=\"Helvetica\" font-weight=\"bold\"  font-size=\"6pt\" >\n " + m05bConstantesInformes.PIE2_E_ACTA ;
			                                tmpFoFileStream.write(sLinea.getBytes());
                   			              sLinea = "	    	</fo:block>\n";
		                                      tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
  			            		tmpFoFileStream.write(sLinea.getBytes());

			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Letra Pequeña 1 Castellano
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
                  		            	// Título Castellano
			                                sLinea = "			<fo:block font-family=\"Helvetica\" font-size=\"6pt\" >\n " + m05bConstantesInformes.PIE1_C_ACTA ;
			                                tmpFoFileStream.write(sLinea.getBytes());
                   			              sLinea = "	    	</fo:block>\n";
		                                      tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
  			            		tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Letra Pequeña 2 Castellano
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
                  		            	// Título Castellano
			                                sLinea = "			<fo:block font-family=\"Helvetica\" font-size=\"6pt\">\n " + m05bConstantesInformes.PIE2_C_ACTA ;
			                                tmpFoFileStream.write(sLinea.getBytes());
                   			              sLinea = "	    	</fo:block>\n";
		                                      tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
  			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());



                        //PIE DE PAGINA Pie
					sLinea = "      <fo:block-container position=\"absolute\" top=\"28.1cm\" left=\"0.65cm\" width=\"15cm\" height=\"2cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"160mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"7pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		                              // FIRMA CASTELLANO
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
                                          //Fiema en Castellano
			            			sLinea = "	    <fo:table-cell >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block text-align=\"center\">" + m05bConstantesInformes.PIE_ASIGNACION+ "</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());	
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());

		         sLinea = "      </fo:flow>\n";
                 tmpFoFileStream.write(sLinea.getBytes());
                 
         	 sLinea = "   </fo:page-sequence>\n";
             tmpFoFileStream.write(sLinea.getBytes());

         sLinea = "</fo:root>\n";
         tmpFoFileStream.write(sLinea.getBytes());

         tmpFoFileStream.close();

         FileInputStream file = new FileInputStream(sFoFileDir + tmpFoFile.getName());

         /**/
         boolean obtenerFichero = false;
         String aux = request.getParameter("ObtenerFichero");
         if (aux != null && aux.equals("1")) {
        	 obtenerFichero = true;
         }

         if (obtenerFichero) {
        	 String sAccion = request.getParameter("Accion");
        	 ByteArrayOutputStream ficheroPDF = obtenerFichero(new InputSource(file), response);
        	 String encoded = encodeBase64(ficheroPDF);

        	 tmpFoFile.delete();

        	 request.setAttribute("pdfFicheroEntDev", encoded);
             String sCodigo = request.getParameter("Codigo");
			 String sURL = response.encodeRedirectURL("m05bAsignacionesJsp.jsp" + "?Codigo=" + sCodigo + "&Accion=" + sAccion);

			 RequestDispatcher rd = request.getRequestDispatcher(sURL);
			 rd.forward(request, response);
         } else {
        	 renderFO(new InputSource(file), response);
        	 
             tmpFoFile.delete();

             response.flushBuffer();
         }
         /**/
      }
      catch (Exception ex)
      {
    	  try {
    		  response.sendRedirect("m05bError.jsp");
    	  } catch (IOException e) {
    		  // TODO Auto-generated catch block
    		  miLog.addTraza(e);
    	  }
      }
   }

    /**
     * renders an FO inputsource into a PDF file which is rendered
     * directly to the response object's OutputStream
     */
    public void renderFO(InputSource foFile, HttpServletResponse response) throws ServletException
    {
        try
        {
            ByteArrayOutputStream out = new ByteArrayOutputStream();

	    	response.reset();
            OutputStream oOut=response.getOutputStream();
            BufferedOutputStream bOut=new BufferedOutputStream(oOut);
            Driver driver = new Driver(foFile, out);
            driver.setRenderer(Driver.RENDER_PDF);

            Map m = new HashMap();
            m.put("pdf-a-mode", "PDF/A-1b");
            driver.getRenderer().setOptions(m); 

            driver.run();

            //foUserAgent.getRendererOptions().put("pdf-a-mode","PDF/A-1b");
            //userAgent.getRendererOptions().put("pdf-x-mode", "PDF/X-3:2003");

            response.setContentLength(out.size());
            response.setContentType("application/pdf");

            bOut.write(out.toByteArray());
            out.close();
            bOut.flush();
            bOut.close();
        	//response.flushBuffer();
        }
        catch (Exception ex)
        {
            throw new ServletException(ex);
        }
    }

    
    public ByteArrayOutputStream obtenerFichero(InputSource foFile, HttpServletResponse response) throws ServletException
    {
    	try
    	{
    		ByteArrayOutputStream out = new ByteArrayOutputStream();

    		Driver driver = new Driver(foFile, out);
			driver.setRenderer(Driver.RENDER_PDF);

			Map m = new HashMap();
			m.put("pdf-a-mode", "PDF/A-1b");
			driver.getRenderer().setOptions(m); 

			driver.run();

			return out;
    	} catch (Exception ex) {
    		throw new ServletException(ex);
    	}
    }

    public String encodeBase64(ByteArrayOutputStream pdf) {

    	BASE64Encoder encoder = new BASE64Encoder();

    	byte[] bytespdf;

   		bytespdf = pdf.toByteArray();

    	return encoder.encodeBuffer(bytespdf);
    }
}