Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Sonal Sinha
How to generate Reports in Liferay 6.1
22 de Março de 2013 01:33
Resposta

Sonal Sinha

Ranking: New Member

Mensagens: 11

Data de entrada: 16 de Janeiro de 2013

Mensagens recentes

I want to generate a pdf on click of a button in a portlet. The portlet shows information in table form i want to export that data to pdf.
Please help me how to proceed further.
I am attaching a screen shot of portlet for the reference.
Anexo

Anexos: export to pdf.png (11,9k)
Subhash Pavuskar
RE: How to generate Reports in Liferay 6.1
22 de Março de 2013 02:02
Resposta

Subhash Pavuskar

Ranking: Regular Member

Mensagens: 234

Data de entrada: 12 de Março de 2012

Mensagens recentes

Hi,
Try using Jasper Report !! Click Here
Ravi Teja
RE: How to generate Reports in Liferay 6.1
22 de Março de 2013 04:39
Resposta

Ravi Teja

Ranking: New Member

Mensagens: 21

Data de entrada: 9 de Julho de 2012

Mensagens recentes

Sonal Sinha:
I want to generate a pdf on click of a button in a portlet. The portlet shows information in table form i want to export that data to pdf.
Please help me how to proceed further.
I am attaching a screen shot of portlet for the reference.


Hi Sonal,

Check this url.

may be this will help to you.

I implemented and generated the pdf using this(i also done on click event giving pop-window and ask for download)

Here i am attaching my Sample Report-generation portlet.
Plz find attachment.(i done in 6.0)
Anexos: pdfgeneration-portlet.rar (9.283,4k)
Meera Prince
RE: How to generate Reports in Liferay 6.1
22 de Março de 2013 06:46
Resposta

Meera Prince

Ranking: Liferay Legend

Mensagens: 1110

Data de entrada: 8 de Fevereiro de 2011

Mensagens recentes

Hi
Use flying saucer library so that you can directly send html then that will be converted as PDF.

http://today.java.net/pub/a/today/2007/06/26/generating-pdfs-with-flying-saucer-and-itext.html

https://code.google.com/p/flying-saucer/wiki/FAQ

http://flyingsaucerproject.github.com/flyingsaucer/r8/guide/users-guide-R8.html


Regards,
Meera Prince
Kalai Arasan
RE: How to generate Reports in Liferay 6.1
1 de Outubro de 2013 01:33
Resposta

Kalai Arasan

Ranking: Regular Member

Mensagens: 103

Data de entrada: 2 de Janeiro de 2013

Mensagens recentes

Hi!
I tried this pdfgeneration portlet for generate pdf nothing is working. Please tell me what is wrong?
Sharad Sinha
RE: How to generate Reports in Liferay 6.1
3 de Outubro de 2013 02:08
Resposta

Sharad Sinha

Ranking: Junior Member

Mensagens: 44

Data de entrada: 7 de Março de 2013

Mensagens recentes

Hi Sonal,

Try with this code and let me know it is working or not..

Write this code in your java class and call this java method when you click on export PDF button.


Thanks & Regards
Sharad Sinha
Anexos: GeneratePdf.java (0,8k), itext-2.1.7.jar (1.103,6k)
Meera Prince
RE: How to generate Reports in Liferay 6.1
3 de Outubro de 2013 06:05
Resposta

Meera Prince

Ranking: Liferay Legend

Mensagens: 1110

Data de entrada: 8 de Fevereiro de 2011

Mensagens recentes

Sonal Sinha:
I want to generate a pdf on click of a button in a portlet. The portlet shows information in table form i want to export that data to pdf.
Please help me how to proceed further.
I am attaching a screen shot of portlet for the reference.



http://www.liferaysavvy.com/2013/09/liferay-pdf-generation-from-html-using.html
Mohammad Azharuddin
RE: How to generate Reports in Liferay 6.1
13 de Novembro de 2013 21:58
Resposta

Mohammad Azharuddin

Ranking: Expert

Mensagens: 477

Data de entrada: 17 de Setembro de 2012

Mensagens recentes

Hi when i try ur code i can able to save pdf file in my machine and read it ..but when i try to download i getting below error .....PLEASE HELP

Adobe Reader could not open 'test(1).pdf' because it is either not a supported file type or because the file has been damaged (for example. it was sent as an email attachment and wasn't correctly decoded).



String sb= "<html><body> This is my Project </body></html>";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream file = new FileOutputStream(new File("E:\\Test.pdf"));
Document document = new Document();
if i try PdfWriter writer = PdfWriter.getInstance(document, file);// file is saving in machine can able to read...unable read downloaded file
if i try replace above line with this PdfWriter writer = PdfWriter.getInstance(document, baos );// file is saving in machine ,not able to read from both location
document.open();
InputStream is = new ByteArrayInputStream(sb.toString().getBytes());
XMLWorkerHelper xmlWorkerHelper=XMLWorkerHelper.getInstance();
// XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
xmlWorkerHelper.parseXHtml(writer, document, new StringReader(sb.toString()));

resourceResponse.setContentType("application/pdf");
resourceResponse.setProperty(HttpHeaders.CONTENT_DISPOSITION,
"attachement;filename=test");
resourceResponse.addProperty(HttpHeaders.CACHE_CONTROL,
"max-age=3600, must-revalidate");
resourceResponse.setContentLength(baos.size());
OutputStream out = (OutputStream) resourceResponse.getPortletOutputStream();
baos.writeTo(out);
out.flush();
out.close();
document.close();
file.close();
Mohammad Azharuddin
RE: How to generate Reports in Liferay 6.1
13 de Novembro de 2013 08:22
Resposta

Mohammad Azharuddin

Ranking: Expert

Mensagens: 477

Data de entrada: 17 de Setembro de 2012

Mensagens recentes

meera prince:
Sonal Sinha:
I want to generate a pdf on click of a button in a portlet. The portlet shows information in table form i want to export that data to pdf.
Please help me how to proceed further.
I am attaching a screen shot of portlet for the reference.



http://www.liferaysavvy.com/2013/09/liferay-pdf-generation-from-html-using.html


Please make sure that what code u have given works
Mohammad Azharuddin
RE: How to generate Reports in Liferay 6.1
13 de Novembro de 2013 23:16
Resposta

Mohammad Azharuddin

Ranking: Expert

Mensagens: 477

Data de entrada: 17 de Setembro de 2012

Mensagens recentes

Hi Guys

Any updates
Mohammad Azharuddin
RE: How to generate Reports in Liferay 6.1
14 de Novembro de 2013 04:19
Resposta

Mohammad Azharuddin

Ranking: Expert

Mensagens: 477

Data de entrada: 17 de Setembro de 2012

Mensagens recentes

This is working


String html= "<html><body> This is my Project </body></html>";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream portletOutputStream=null;
Document document=null;
try {
document=new Document();
PdfWriter pdfWriter=PdfWriter.getInstance(document, baos);
document.open();
XMLWorkerHelper xmlWorkerHelper=XMLWorkerHelper.getInstance();
xmlWorkerHelper.parseXHtml(pdfWriter, document, new StringReader(html.toString()));
document.close();
resourceResponse.setContentType("application/pdf");
resourceResponse.setProperty(HttpHeaders.CONTENT_DISPOSITION,
"attachement;filename=test");
resourceResponse.addProperty(HttpHeaders.CACHE_CONTROL,
"max-age=3600, must-revalidate");
resourceResponse.setContentLength(baos.size());
portletOutputStream = (OutputStream) resourceResponse.getPortletOutputStream();
baos.writeTo(portletOutputStream);
portletOutputStream.flush();

} catch (Exception e) {
_log.error(e.getMessage());
}
finally{
baos.close();
portletOutputStream.close();
}
Anexos: itextpdf-5.4.2.jar (1.879,0k), xmlworker-5.4.4.jar (222,3k)
asif aftab
RE: How to generate Reports in Liferay 6.1
27 de Novembro de 2013 03:31
Resposta

asif aftab

Ranking: Junior Member

Mensagens: 95

Data de entrada: 2 de Setembro de 2013

Mensagens recentes

This code is working too


In this application I am first take data from a table studentdetails and then printing its value to pdf.
Description of table
table name: studentdetails
column name:
FatherName, Emailid, firstlanguage, lastschoolname, mothername, nationality, religion, secondlanguage, sex, stream, studentid, date of birth, sname
"Please add the attach .jar file in your lib file manually
My action class
  1
  2package com.test.pdf;
  3
  4import java.io.IOException;
  5
  6import javax.portlet.PortletException;
  7import javax.portlet.PortletSession;
  8import javax.portlet.ResourceRequest;
  9import javax.portlet.ResourceResponse;
 10
 11import pdf.ashraf.userdata.model.studentDetails;
 12import pdf.ashraf.userdata.service.studentDetailsLocalServiceUtil;
 13
 14
 15import com.lowagie.text.Anchor;
 16import com.lowagie.text.DocumentException;
 17import com.lowagie.text.Font;
 18import com.lowagie.text.FontFactory;
 19import com.lowagie.text.PageSize;
 20import com.lowagie.text.Paragraph;
 21import com.lowagie.text.Phrase;
 22import com.lowagie.text.Rectangle;
 23import com.lowagie.text.pdf.CMYKColor;
 24import com.lowagie.text.pdf.PdfPCell;
 25import com.lowagie.text.pdf.PdfPTable;
 26import com.lowagie.text.pdf.PdfWriter;
 27import java.io.ByteArrayOutputStream;
 28import java.io.File;
 29import java.io.FileOutputStream;
 30import java.io.FileWriter;
 31import java.io.IOException;
 32import java.io.OutputStream;
 33import java.io.PrintWriter;
 34import java.io.StringReader;
 35import java.util.ArrayList;
 36import java.util.Iterator;
 37import java.util.List;
 38
 39import com.liferay.portal.kernel.exception.PortalException;
 40import com.liferay.portal.kernel.exception.SystemException;
 41import com.liferay.portal.kernel.servlet.HttpHeaders;
 42import com.liferay.portal.kernel.util.Base64;
 43import com.liferay.portal.kernel.util.StringPool;
 44import com.liferay.util.bridges.mvc.MVCPortlet;
 45
 46
 47public class PdfAsfrafPortlet extends MVCPortlet
 48{
 49    public void serveResource(ResourceRequest request, ResourceResponse response)
 50        throws PortletException, IOException
 51            {
 52               
 53                try
 54                {
 55                    createPDF(request,response);
 56                }
 57                catch (SystemException e)
 58                {                   
 59                    e.printStackTrace();
 60                }
 61            }
 62   
 63public void createPDF(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
 64    throws IOException, PortletException, SystemException
 65        {
 66        try
 67          {
 68           resourceRequest.setCharacterEncoding(StringPool.UTF8);                
 69           com.lowagie.text.Document document = new com.lowagie.text.Document();    //blank pdf created
 70           ByteArrayOutputStream baos = new ByteArrayOutputStream();
 71           PdfWriter.getInstance(document, baos);                        //predefine class PdfWriter calls static method getInstance
 72           document.open();                                                //open pdf in write method
 73           PdfPTable table= new PdfPTable(13);                            //creating a pdf table having single column hence PdfPTable table= new PdfPTable(1);
 74           table.setWidthPercentage(100);                                //setting width size                                            //to design cell
 75           table.addCell("FatherName");        //adding value in row. here number of rows is depends on the number of      table.addcell();
 76           table.addCell("Emailid");
 77           table.addCell("firstlanguage");
 78           table.addCell("lastschoolname");
 79           table.addCell("mothername");                                           //adding value in row
 80           table.addCell("nationality");
 81           table.addCell("religion");
 82           table.addCell("secondlanguage");
 83           table.addCell("gender");
 84           table.addCell("stream");
 85           table.addCell("studentid");
 86           table.addCell("date of birth");
 87           table.addCell("sname");
 88          
 89            List<studentDetails> tbl=null;
 90            tbl=studentDetailsLocalServiceUtil.findWholeTbl();       //to fetch whole table
 91            if(tbl!=null)
 92            {
 93            System.out.println("tbl size:  "+tbl.size());
 94            Iterator<studentDetails> it=tbl.iterator();
 95            while(it.hasNext())
 96            {
 97                studentDetails obj=it.next();
 98               
 99                table.addCell(obj.getFatherName());
100                table.addCell(obj.getEmailId());
101                table.addCell(obj.getFirstLanguage());
102                table.addCell(obj.getLastSchoolName());
103                table.addCell(obj.getMotherName());
104                table.addCell(obj.getNationality());
105                table.addCell(obj.getReligion());
106                table.addCell(obj.getSecondLanguage());
107                table.addCell(obj.getSex());
108                table.addCell(obj.getStream());
109                long l=obj.getStudentId();
110                String sl=String.valueOf(l);
111                table.addCell(sl);
112                String sd=String.valueOf(obj.getDateOfBirth());
113                table.addCell(sd);
114                table.addCell(obj.getSName());
115               
116               
117            }//while
118            }//if
119            
120           document.add(table);                                            //adding table to created pdf document
121           document.close();                                            //we have to first close the document
122           String fileName="attachment;filename=ashraf.pdf";            //filename
123           resourceResponse.setContentType("application/pdf");            //setting the content type either application or pdf(Portable Document Format)
124           resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION, fileName);    //
125           OutputStream out = resourceResponse.getPortletOutputStream();
126           byte[] downloadBytes = Base64.decode((String) resourceRequest.getAttribute("fileToDownloadBase64"));
127           out.write(downloadBytes);
128           baos.writeTo(out);
129           out.flush();
130           out.close();
131          }
132          catch (Exception e)
133          {
134           e.printStackTrace();
135          }
136         }//createPdf
137}//end of class


and my view.jsp

 1
 2<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 3
 4<portlet:defineObjects />
 5
 6This is the <b>Pdf Asfraf Portlet</b> portlet in View mode.
 7<portlet:resourceURL var="submitFormDetailsResourceURL" id="appform" escapeXml="false"/>
 8<br><br><br>
 9<form action="<%=submitFormDetailsResourceURL.toString() %>" method="post">
10<h2>This project working fine</h2>
11<p>Here I am retreiving data from table asif_studentDetails and then just publish that data in pdf format
12<input type="submit" value="Download" name="submitbutton">
13</form>
Anexos: itext-1.1.4.jar (1.294,7k)
Meera Prince
RE: How to generate Reports in Liferay 6.1
27 de Novembro de 2013 17:55
Resposta

Meera Prince

Ranking: Liferay Legend

Mensagens: 1110

Data de entrada: 8 de Fevereiro de 2011

Mensagens recentes

Hi

Go through following link..

Use JTidy with flying saucer to generate pdf from HTML..

Use following portlet jar files then problem will be solved....

http://www.liferaysavvy.com/2013/11/export-journal-content-as-pdf-in-liferay.html
Subhash patel
Forget password is not working
27 de Novembro de 2013 22:45
Resposta

Subhash patel

Ranking: New Member

Mensagens: 1

Data de entrada: 13 de Fevereiro de 2013

Mensagens recentes

Hello everyone my forget password is not working plz give me any suggestion.......
Mohammad Azharuddin
RE: Forget password is not working
29 de Novembro de 2013 02:29
Resposta

Mohammad Azharuddin

Ranking: Expert

Mensagens: 477

Data de entrada: 17 de Setembro de 2012

Mensagens recentes

Hi Subhash patel

Please post it as new thread... read this