Fórum

I downloaded this...

asif aftab, modificado 10 Anos atrás.

I downloaded this...

Regular Member Postagens: 123 Data de Entrada: 02/09/13 Postagens Recentes
I downloaded this code and there is no error but when ever I run this code it just simply create a pdf file with name test but when I tried to open this
pdf it is showing that "abode is unable to open this file, either file is damage or not supporting format"
is any one can help me in this regard
this is my action class


package com.test.pdf;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringBufferInputStream;

import javax.portlet.PortletException;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.xhtmlrenderer.pdf.ITextRenderer;

import com.liferay.portal.kernel.servlet.HttpHeaders;
import com.liferay.util.bridges.mvc.MVCPortlet;

/**
 * Portlet implementation class PdfAction
 */
public class pdfPortlet extends MVCPortlet 
{
 	public void serveResource(ResourceRequest request, ResourceResponse response)
		throws PortletException, IOException
		{
		response.setContentType("application/pdf");
		response.setProperty(HttpHeaders.CONTENT_DISPOSITION,"attachement;filename=test");
		try {
			StringBuffer buf = new StringBuffer();
			buf.append("");
			buf.append("");
			buf.append("<table width="720px" border="0"><tbody><tr><td align="center"><b>This is Test</b></td></tr></tbody></table>");
			buf.append("<table width="720px" border="0"><tbody><tr><td><b>Organization Name:Test</b></td></tr></tbody></table>");
			buf.append("<table align="center" border="1">");
			buf.append("<tbody><tr><td width="400px">Name:</td><td width="400px">Meera Prince</td></tr>");   
			buf.append("<tr><td width="400px">Location:</td><td width="400px">Hong Kong</td></tr>");  
			buf.append("<tr><td width="400px">Email:</td><td width="400px">meera.success@gmail.com</td></tr>");  
			buf.append("<tr><td width="400px">Availeble Time:</td><td width="400px">You can knock door any time.....</td></tr>");  
			buf.append("</tbody></table>");
			//buf.append("Hello World, iText");
			buf.append("");
			buf.append("");
			System.out.println("$$$$$$$$$$$$$from here");
			byte[] bytes = buf.toString().getBytes();
		    InputStream inputStream = new ByteArrayInputStream(bytes);
			DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
			org.w3c.dom.Document doc = builder.parse(inputStream);
			ITextRenderer renderer = new ITextRenderer();
			renderer.setDocument(doc, null);
			renderer.layout();
			OutputStream os = response.getPortletOutputStream();
			renderer.createPDF(os);
			
			//renderer.createPDF(os);
			os.close();
			}
			catch (Exception ex)
			{
			ex.printStackTrace();
			}

	}
}

and this is my jsp page

&lt;%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %&gt;
&lt;%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %&gt;
&lt;%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %&gt;
&lt;%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %&gt;
&lt;%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %&gt;
&lt;%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %&gt;
&lt;%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %&gt;
&lt;%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %&gt;
&lt;%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %&gt;
<portlet:defineobjects />
<h1>Liferay PDF Generation from HTML Using Flying Saucer</h1>

<portlet:resourceurl var="submitFormDetailsResourceURL" id="appform" escapeXml="false" />
<a href="<%=submitFormDetailsResourceURL%>" target="_blank"><h2>Click Here To get PDF</h2></a>

I am trying this one but I am not getting what is the problem please help me
thumbnail
mohammad azaruddin, modificado 10 Anos atrás.

RE: I downloaded this...

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens Recentes
asif aftab, modificado 10 Anos atrás.

RE: I downloaded this...

Regular Member Postagens: 123 Data de Entrada: 02/09/13 Postagens Recentes
Thanks azharuddin for your reply. My problem already solved but by using different code and thanks for the link too.