开发者

How to export javascript generated report to pdf?

I made a reporting engine with javascrip开发者_如何学JAVAt for my project... The problem is with printing.. Although with page-break and css i can produce a good looking report, i want to export that report to a pdf in order to be printed better without ,the url,page title and other stuff that browsers add. Note in Chrome there isnt page setup!!!

I am using java for server side.

i think sending via ajax the Html of the report somehow and return a url for the pdf report maybe... i am looking for a good tool for this thank you


If you do send the data server-side, iText is a great free, open source library for generating PDFs from Java.

What I do is generate the report directly to the response stream after setting the content type of the response to application/pdf and setting a Content-Disposition header to either attachment; filename=foo.pdf (if I want to hint to the browser that it should offer a download) or inline; filename=foo.pdf if I want to hint to the browser to show it in the brower's UI.

For what you're doing, perhaps you want to write a file server-side in case someone requests another copy of the report with the same parameters and such, but if not, writing directly to the servlet's OutputStream would be the way to go.

(Caveat: I have to admit not having actually used the Java version of iText, but only because I haven't needed to generate PDFs from Java yet. I'm doing the above using iTextSharp, the .Net port of iText, from server-side Javascript [yes, really] and it works a treat.)


I'd rather generate the report on the server side, based on the data, using JasperReports.

You can send the html to server side and use iText or JasperReports or OpenOffice api to generate a pdf.


It depends on how much you have invested in your Javascript solution. Typically I would agree that it is much better to produce the report server-side since you'll have more options and probably a more maintainable result using Jasper or Docmosis or somesuch.

You could send the html of the page back to the server and have a system there that can read it and render it into PDF, but you've done a round-trip more than you need to, and it sounds like a harder and more fragile way to produce a PDF.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜