0

How Can we display the data of database into a pdf format ?

asked 2012-09-17 13:23:09 +0800

dua gravatar image dua
27 1

Am trying to get the data from database and showing up in a pdf format ?
how can we do it ?

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2012-09-17 17:24:19 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Please Have a Look Here. It will help you

link publish delete flag offensive edit

answered 2012-09-18 06:28:21 +0800

dua gravatar image dua
27 1

actually this is only exporting the file to pdf. what i want is to display the data in pdf format on zul page.
can anyone help me out

link publish delete flag offensive edit

answered 2012-09-18 08:06:20 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Google for iText . It's a library for pdf manipulation. Hope this can help you

best
Stephan

link publish delete flag offensive edit

answered 2012-09-25 12:07:34 +0800

dua gravatar image dua
27 1

i've created a document using pdf writer. now the problem is coming how to show that pdf data in zul file ?

will this code will do ?
<?page title="Home" contentType="application/pdf; charset=UTF-8"?>

or do we have to bind with some label or any other control ?
is there any simple way like we do in jsp
response.setContentType="application/pdf" ?

link publish delete flag offensive edit

answered 2012-09-26 05:55:44 +0800

dua gravatar image dua
27 1

does any body knows the solution of it ?
plz reply asap

link publish delete flag offensive edit

answered 2012-10-03 14:41:53 +0800

aros54 gravatar image aros54
66

A simple way to embed a pdf file into a zul page is to use the iframe component. To set the iframe content property build a org.zkoss.util.media.AMedia class instance. This class has a lot of constructors that can be used depending on which type of media you used to store your pdf information. For instance, if you used iText tool - that in my opinion is a pretty good choice to create and manage pdf files - you probably have a ByteArrayOutputStream. Let's call it "baos":

Media content = new AMedia("filename", "pdf", "application/pdf", baos.getBytes());

However I prefer to display the pdf files in a stand alone browser window. A pdf file is generally a report or a generated form printout and could be huge in size. I would like the user has the full control of all the browser pdf plugin capabilities: copy, save, print, search, etc. To display a pdf file in a stand alone browser window I make use of a simple servlet:

public class ReportServlet extends GenericServlet {
	
	private static final long serialVersionUID = 1L;
	private static final Log log = Log.lookup(ReportServlet.class);
	public static final String REPORT_STREAM = "report-stream";

	public void service(ServletRequest request, ServletResponse response)
			throws ServletException, IOException {
		HttpServletRequest httpRequest = (HttpServletRequest)request;
		HttpServletResponse httpResponse = (HttpServletResponse)response;
		ByteArrayOutputStream baos = (ByteArrayOutputStream)httpRequest.getSession().getAttribute(REPORT_STREAM);
		if (baos != null) {
			byte[] data = baos.toByteArray();
			httpResponse.setHeader("Content-disposition", "filename=report.pdf");
			httpResponse.setContentType("application/pdf");
			ServletOutputStream out = httpResponse.getOutputStream();
			out.write(data);
			httpRequest.getSession().setAttribute(REPORT_STREAM, null);
		} else {
			log.info("No input found.");
		}
	}

}

To show the pdf I send a redirect to the servlet url from my application code:

		if (baos.size() > 0) {
			Sessions.getCurrent().setAttribute(ReportServlet.REPORT_STREAM, baos);
			Executions.getCurrent().sendRedirect("/report", "_blank");
		}

This opens a new browser window containing the pdf content. Do not forget to declare the servlet in your web.xml file.

Hope this can help.
/Adriano

link publish delete flag offensive edit

answered 2012-10-08 12:15:59 +0800

dua gravatar image dua
27 1

Thank aros54
i've also used the some how the same way like your approach.
thanks for reply btw

link publish delete flag offensive edit

answered 2012-10-08 17:34:21 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

@Dua Please post solution so that it will help some other developer.
thanks

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-09-17 13:23:09 +0800

Seen: 303 times

Last updated: Oct 08 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More