Fórum

How to generate Reports in Liferay 6.1

Sonal Sinha, modificado 11 Anos atrás.

How to generate Reports in Liferay 6.1

New Member Postagens: 11 Data de Entrada: 17/01/13 Postagens 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.
thumbnail
Subhash Pavuskar, modificado 11 Anos atrás.

RE: How to generate Reports in Liferay 6.1

Regular Member Postagens: 234 Data de Entrada: 13/03/12 Postagens Recentes
Hi,
Try using Jasper Report !! Click Here
Ravi Teja, modificado 11 Anos atrás.

RE: How to generate Reports in Liferay 6.1

New Member Postagens: 21 Data de Entrada: 09/07/12 Postagens 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)
thumbnail
Kalai arasan, modificado 10 Anos atrás.

RE: How to generate Reports in Liferay 6.1

Regular Member Postagens: 127 Data de Entrada: 02/01/13 Postagens Recentes
Hi!
I tried this pdfgeneration portlet for generate pdf nothing is working. Please tell me what is wrong?
thumbnail
meera prince, modificado 11 Anos atrás.

RE: How to generate Reports in Liferay 6.1

Liferay Legend Postagens: 1111 Data de Entrada: 08/02/11 Postagens 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
Sharad Sinha, modificado 10 Anos atrás.

RE: How to generate Reports in Liferay 6.1

Junior Member Postagens: 44 Data de Entrada: 08/03/13 Postagens 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
thumbnail
meera prince, modificado 10 Anos atrás.

RE: How to generate Reports in Liferay 6.1

Liferay Legend Postagens: 1111 Data de Entrada: 08/02/11 Postagens 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
thumbnail
mohammad azaruddin, modificado 10 Anos atrás.

RE: How to generate Reports in Liferay 6.1

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens 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();
thumbnail
mohammad azaruddin, modificado 10 Anos atrás.

RE: How to generate Reports in Liferay 6.1

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens 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
thumbnail
mohammad azaruddin, modificado 10 Anos atrás.

RE: How to generate Reports in Liferay 6.1

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens Recentes
Hi Guys

Any updates
thumbnail
mohammad azaruddin, modificado 10 Anos atrás.

RE: How to generate Reports in Liferay 6.1

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens 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();
}
asif aftab, modificado 10 Anos atrás.

RE: How to generate Reports in Liferay 6.1

Regular Member Postagens: 123 Data de Entrada: 02/09/13 Postagens 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

package com.test.pdf;

import java.io.IOException;

import javax.portlet.PortletException;
import javax.portlet.PortletSession;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

import pdf.ashraf.userdata.model.studentDetails;
import pdf.ashraf.userdata.service.studentDetailsLocalServiceUtil;


import com.lowagie.text.Anchor;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.CMYKColor;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.servlet.HttpHeaders;
import com.liferay.portal.kernel.util.Base64;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.util.bridges.mvc.MVCPortlet;


public class PdfAsfrafPortlet extends MVCPortlet
{
	public void serveResource(ResourceRequest request, ResourceResponse response)
		throws PortletException, IOException
			{
				
				try 
				{
					createPDF(request,response);
				} 
				catch (SystemException e) 
				{					
					e.printStackTrace();
				}
			}
	
public void createPDF(ResourceRequest resourceRequest, ResourceResponse resourceResponse) 
	throws IOException, PortletException, SystemException 
		{
		try
		  {
		   resourceRequest.setCharacterEncoding(StringPool.UTF8);                 
		   com.lowagie.text.Document document = new com.lowagie.text.Document();	//blank pdf created 
		   ByteArrayOutputStream baos = new ByteArrayOutputStream();
		   PdfWriter.getInstance(document, baos);						//predefine class PdfWriter calls static method getInstance
		   document.open();												//open pdf in write method
		   PdfPTable table= new PdfPTable(13);							//creating a pdf table having single column hence PdfPTable table= new PdfPTable(1);
		   table.setWidthPercentage(100);								//setting width size											//to design cell
		   table.addCell("FatherName");		//adding value in row. here number of rows is depends on the number of      table.addcell();
		   table.addCell("Emailid");
		   table.addCell("firstlanguage");
		   table.addCell("lastschoolname");
		   table.addCell("mothername");       									//adding value in row 
		   table.addCell("nationality");
		   table.addCell("religion");
		   table.addCell("secondlanguage");
		   table.addCell("gender");
		   table.addCell("stream");
		   table.addCell("studentid");
		   table.addCell("date of birth");
		   table.addCell("sname");
		   
		    List<studentdetails> tbl=null;
			tbl=studentDetailsLocalServiceUtil.findWholeTbl();       //to fetch whole table
			if(tbl!=null)
			{
			System.out.println("tbl size:  "+tbl.size());
			Iterator<studentdetails> it=tbl.iterator();
			while(it.hasNext())
			{
				studentDetails obj=it.next();
				
				table.addCell(obj.getFatherName());
				table.addCell(obj.getEmailId());
				table.addCell(obj.getFirstLanguage());
				table.addCell(obj.getLastSchoolName());
				table.addCell(obj.getMotherName());
				table.addCell(obj.getNationality());
				table.addCell(obj.getReligion());
				table.addCell(obj.getSecondLanguage());
				table.addCell(obj.getSex());
				table.addCell(obj.getStream());
				long l=obj.getStudentId();
				String sl=String.valueOf(l);
				table.addCell(sl);
				String sd=String.valueOf(obj.getDateOfBirth());
				table.addCell(sd);
				table.addCell(obj.getSName());
				
				
			}//while
			}//if
			
		   document.add(table);											//adding table to created pdf document
		   document.close();											//we have to first close the document 
		   String fileName="attachment;filename=ashraf.pdf";			//filename 
		   resourceResponse.setContentType("application/pdf");			//setting the content type either application or pdf(Portable Document Format)
		   resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION, fileName);	//
		   OutputStream out = resourceResponse.getPortletOutputStream();
		   byte[] downloadBytes = Base64.decode((String) resourceRequest.getAttribute("fileToDownloadBase64"));
		   out.write(downloadBytes);
		   baos.writeTo(out);
		   out.flush();
		   out.close();
		  }
		  catch (Exception e)
		  {
		   e.printStackTrace();
		  }
		 }//createPdf
}//end of class
</studentdetails></studentdetails>


and my view.jsp


&lt;%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %&gt;

<portlet:defineobjects />

This is the <b>Pdf Asfraf Portlet</b> portlet in View mode.
<portlet:resourceurl var="submitFormDetailsResourceURL" id="appform" escapeXml="false" />
<br><br><br>
<form action="<%=submitFormDetailsResourceURL.toString() %>" method="post">
<h2>This project working fine</h2>
</form>

Here I am retreiving data from table asif_studentDetails and then just publish that data in pdf format <input type="submit" value="Download" name="submitbutton">

thumbnail
meera prince, modificado 10 Anos atrás.

RE: How to generate Reports in Liferay 6.1

Liferay Legend Postagens: 1111 Data de Entrada: 08/02/11 Postagens 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
thumbnail
Subhash patel, modificado 10 Anos atrás.

Forget password is not working

New Member Postagens: 2 Data de Entrada: 14/02/13 Postagens Recentes
Hello everyone my forget password is not working plz give me any suggestion.......
thumbnail
mohammad azaruddin, modificado 10 Anos atrás.

RE: Forget password is not working

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens Recentes
Hi Subhash patel

Please post it as new thread... read this