Fóruns

Início » Liferay IDE » English

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
asif aftab
I downloaded this...
21 de Novembro de 2013 07:40
Resposta

asif aftab

Ranking: Junior Member

Mensagens: 95

Data de entrada: 2 de Setembro de 2013

Mensagens 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

 1
 2package com.test.pdf;
 3import java.io.ByteArrayInputStream;
 4import java.io.IOException;
 5import java.io.InputStream;
 6import java.io.OutputStream;
 7import java.io.StringBufferInputStream;
 8
 9import javax.portlet.PortletException;
10import javax.portlet.ResourceRequest;
11import javax.portlet.ResourceResponse;
12import javax.xml.parsers.DocumentBuilder;
13import javax.xml.parsers.DocumentBuilderFactory;
14
15import org.xhtmlrenderer.pdf.ITextRenderer;
16
17import com.liferay.portal.kernel.servlet.HttpHeaders;
18import com.liferay.util.bridges.mvc.MVCPortlet;
19
20/**
21 * Portlet implementation class PdfAction
22 */
23public class pdfPortlet extends MVCPortlet
24{
25     public void serveResource(ResourceRequest request, ResourceResponse response)
26        throws PortletException, IOException
27        {
28        response.setContentType("application/pdf");
29        response.setProperty(HttpHeaders.CONTENT_DISPOSITION,"attachement;filename=test");
30        try {
31            StringBuffer buf = new StringBuffer();
32            buf.append("<html>");
33            buf.append("<body>");
34            buf.append("<table width='720px' border='0' ><tr><td align='center'><b>This is Test</b></td></tr></table>");
35            buf.append("<table  width='720px' border='0'><tr><td><b>Organization Name:Test</b></td></tr></table>");
36            buf.append("<table align='center' border='1'>");
37            buf.append("<tr><td width='400px'>Name:</td><td width='400px'>Meera Prince</td></tr>");   
38            buf.append("<tr><td width='400px'>Location:</td><td width='400px'>Hong Kong</td></tr>"); 
39            buf.append("<tr><td width='400px'>Email:</td><td width='400px'>meera.success@gmail.com</td></tr>"); 
40            buf.append("<tr><td width='400px'>Availeble Time:</td><td width='400px'>You can knock door any time.....</td></tr>"); 
41            buf.append("</table>");
42            //buf.append("Hello World, iText");
43            buf.append("</body>");
44            buf.append("</html>");
45            System.out.println("$$$$$$$$$$$$$from here");
46            byte[] bytes = buf.toString().getBytes();
47            InputStream inputStream = new ByteArrayInputStream(bytes);
48            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
49            org.w3c.dom.Document doc = builder.parse(inputStream);
50            ITextRenderer renderer = new ITextRenderer();
51            renderer.setDocument(doc, null);
52            renderer.layout();
53            OutputStream os = response.getPortletOutputStream();
54            renderer.createPDF(os);
55            
56            //renderer.createPDF(os);
57            os.close();
58            }
59            catch (Exception ex)
60            {
61            ex.printStackTrace();
62            }
63
64    }
65}

and this is my jsp page
 1
 2<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 3<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 4<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 5<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
 6<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
 7<%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %>
 8<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
 9<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
10<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
11<portlet:defineObjects />
12<h1>Liferay PDF Generation from HTML Using Flying Saucer</h1>
13
14<portlet:resourceURL var="submitFormDetailsResourceURL" id="appform" escapeXml="false"/>
15<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
Mohammad Azharuddin
RE: I downloaded this...
21 de Novembro de 2013 21:41
Resposta

Mohammad Azharuddin

Ranking: Expert

Mensagens: 471

Data de entrada: 17 de Setembro de 2012

Mensagens recentes

follow this


HTH
asif aftab
RE: I downloaded this...
27 de Novembro de 2013 03:10
Resposta

asif aftab

Ranking: Junior Member

Mensagens: 95

Data de entrada: 2 de Setembro de 2013

Mensagens recentes

Thanks azharuddin for your reply. My problem already solved but by using different code and thanks for the link too.