Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Trouble showing PDF in a window

    We want to show a pdf generate on the fly through a DMI call.
    We get a valid PDF content (if you save the content, you obtain a "readable" PDF file) but it is showing as a plain text.
    Reading and following instructions in this thread:
    http://forums.smartclient.com/showthread.php?t=3431&highlight=popup+pdf
    we have realized that the problem is not in the way to get the window which shows the PDF, because with your example code occurs the same behaviour.

    Our source code:
    Code:
     
    /****************************************************/
    /****************************************************/	
    //					FORMULARIO
    /****************************************************/
    /****************************************************/
    isc.defineClass("FrmAlbaranParaCliente", "AtlasGenFormulario").addProperties({
     	numCols:2,
     	colWidths:[200,600],
    	/**
    	 *
    	 * 	CAMPOS DEL FORMULARIO
    	 * 
    	 */
    	fields:
    	[
    	 	//
    	 	//	Campos de entrada
    	 	//
    		{
    			name:"PLAZA",
    			title: "Plaza"
    		},
    		{
    			name:"HCARGA",
    			title: "Hoja Carga"
    		},
    		{
    			name:"REPART",
    			title: "Reparto"
    		},
    		{
    			name:"FECHA",
    			title: "Fecha"
    		},
    		//
    		//	Botón
    		// 
    		{
    			_constructor: isc.ToolbarItem,
    			width:110,
    			height: 35,
    			colspan: true,
    			buttons: [{
    				type:"IButton",
    				autoFit:true,
    				title: "Prueba Jasper...",
    				click: llamarImpresion 
    			}]
    		}
    
    	],
    	//
    	//	Inicialización del formulario
    	//
    	initWidget : function () {
    		this.Super("initWidget", arguments);
    	}
    
    
    });
    
    /**
     * 
     * 		FUNCION DE LLAMADA A LA IMPRESION 
     * 
     */
    function llamarImpresion (form, item) {
    
    	var plaza = form.getField("PLAZA").getValue();
    	var hcarga = form.getField("HCARGA").getValue();
    	var repart = form.getField("REPART").getValue();
    	var fecha = form.getField("FECHA").getValue();
    
    	isc.DMI.call({
    		appID: "AlbaranParaCliente",
    		className: "com.redur.impresion.AlbaranParaCliente",
    		methodName: "imprimeAlbaranCliente",
    		arguments: [plaza, 
    		            hcarga,
    		            repart,
    		            fecha
    		],
    		callback : function (response, data) {
    			isc.HTMLPane.create({
    				autoDraw: true,
    			    overflow: "auto"
    				
    			}).setContents(data); // If we replace here this sentence by --> }).setContentsURL('http://www.smartclient.com/devcenter/isomorphicSDK/docs/SmartClient_Quick_Start_Guide.pdf'); 
    								  // We get the same result.
    		},
    		requestParams: { willHandleError: true, 
    						 showPrompt: true
    		}
    	});
    
    }// Fin funcion llamadaPLWS
    What is wrong?
    How can we achieve our objective?
    We attach a screen capture of both result (loading your PDF -Capture1.jpg, and loading our result -Capture2.jpg).





    We are working under:
    v9.1d_2014-02-22/PowerEdition Development SC and IExplrorer 10.0.9200 navigator, Eclipse Helios and Tomcat 7.0.28
    Attached Files

    #2
    The difference between your example and this thread is that you don't have contentsType:"page" specified on your HTMLPane.

    This is required - it makes the HTMLPane actually render out an IFrame, with the appropriate src, so the pdf file loads as a separate document, causing the native browser behavior to handle it automatically and display it in a PDF viewer.

    Comment


      #3
      Well, I have changed it, and now it works with setContentsURL, but does not with setContents...
      My data object which is passing as parameter to setContents is ok and creates a right pdf file from it.
      I must return the PDF object in any specific way?
      This is our java class to generate the PDF:

      Code:
      package com.redur.impresion;
      
      import java.io.File;
      import java.io.IOException;
      import java.io.StringReader;
      import java.io.StringWriter;
      import java.sql.Connection;
      import java.sql.SQLException;
      import java.util.ArrayList;
      import java.util.Arrays;
      import java.util.HashMap;
      import java.util.List;
      import java.util.Locale;
      
      import javax.servlet.ServletOutputStream;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;
      
      import net.sf.jasperreports.engine.JRException;
      import net.sf.jasperreports.engine.JRParameter;
      import net.sf.jasperreports.engine.JasperCompileManager;
      import net.sf.jasperreports.engine.JasperExportManager;
      import net.sf.jasperreports.engine.JasperFillManager;
      import net.sf.jasperreports.engine.JasperPrint;
      import net.sf.jasperreports.engine.JasperReport;
      import net.sf.jasperreports.engine.data.JRXmlDataSource;
      import net.sf.jasperreports.engine.export.JRPdfExporter;
      import net.sf.jasperreports.engine.util.JRLoader;
      
      import org.springframework.web.context.ContextLoader;
      import org.springframework.web.context.WebApplicationContext;
      import org.w3c.dom.Document;
      import org.xml.sax.InputSource;
      
      import com.isomorphic.datasource.DSRequest;
      import com.isomorphic.datasource.DSResponse;
      import com.isomorphic.rpc.RPCManager;
      import com.isomorphic.servlet.RequestContext;
      import com.isomorphic.xml.XML;
      import com.redur.interfaz.dao.ITemplateGenericDao;
      import com.redur.utilities.JasperMultiImpresion;
      import com.redur.utils.beans.Response;
      
      
      public class AlbaranParaCliente {
      
      	@SuppressWarnings({ "rawtypes", "unused", "deprecation" })
      	public void imprimeAlbaranCliente (String plaza, String hcarga, String repart, String fecha,
      									   RPCManager rpc, HttpServletRequest servletRequest, HttpServletResponse response) throws Exception{	
      		DSResponse res = null;
      		Document document = null;
      		StringWriter sw = new StringWriter();
      		
      		try {
      	        rpc.doCustomResponse();
      	        
      			List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();
      			response.setContentType("application/pdf");
      			ServletOutputStream servletOutputStream = response.getOutputStream();
      			Response objResponse = null;
      			
      			HashMap<String, HashMap<String, Object>>  objConfiguracionReport = new HashMap<String, HashMap<String, Object>>();
      			HashMap<String, Object> hashParameters = new HashMap<String, Object>();
      			
      			hashParameters.put(JRParameter.REPORT_LOCALE, new Locale("es"));
      			hashParameters.put("PLAZA",  plaza);
      			hashParameters.put("HCARGA", Integer.parseInt(hcarga));
      			hashParameters.put("REPART", repart);
      			hashParameters.put("FECHA",  fecha);
      			objConfiguracionReport.put("PARAMETERS", hashParameters);
      			
      			String rutaReport = "//report//hcarga1.jasper";
      			String ruta = servletRequest.getRealPath(rutaReport); 
      			File reportFile = new File(ruta);
      			
      	        final WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
      	        ITemplateGenericDao objetoDao = (ITemplateGenericDao)context.getBean("TemplateDao");
      	        Connection conn = objetoDao.getDataSource().getConnection();
      	        JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());
      	        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,hashParameters,conn);
      	        
      			jasperPrintList.add(jasperPrint); 
      			
      			objResponse =  JasperMultiImpresion.generaMultiInformeJasper (jasperPrintList, servletOutputStream, false, "Impresora", 1);
      			final JRPdfExporter  exporter = (JRPdfExporter) objResponse.getObjResult();
      			exporter.exportReport();
              } catch (Exception e) {
              	System.out.println(e.getStackTrace());
              }
      	}
      }

      Comment


        #4
        setContents() won't work because you're essentially populating an HTML DOM element with the raw content of the .pdf file so the browser renders it as plain text / HTML.
        contentsURL works because the browser gets an actual pdf document back as the entire response for the page request, and natively handles showing this in the pdf-viewer.

        In short you need to use contentsURL and load the PDF file that way.

        Your options therefore would be to:

        - EITHER: assemble a URL which would kick off the request to build and stream the pdf file, and assign the contentsURL of the HTMLPane directly to this. The target URL could hit the IDACall servlet (with url parameters), or you could have your own server side filter or servlet to handle the request.

        - OR: Have your DMI call generate the PDF the way it currently does, but instead of streaming it back, store this somewhere like a temp DB table, or the session, and have the DMI return a URL to the browser which will return the stored file. Then set the contentsURL of the HTMLPane to that target URL to pick up and display the PDF.

        Comment

        Working...
        X