How to display MS-Excel and PDF document in web browser? - java

In the project I'm currently working on need to display pdf or excel files to users in their web browser.
We are using java to build up server side and jquery as main js lib for front-end.
What should I do to make this possible?
Or say, what jar or js do I need to rely on (perferably a js lib, but, well.. I have no clue right now..)?
Thanks in advance. :)

It's simple buddy, follow these steps:
Open http://www.scribd.com/
Sign up
Sign in
Upload your excel or pdf file
Get it's iframe code
Place the iframe code in your webpage.
Done

Here are some few clews :
For pdf you can use the built-in of your browser if any, or you could use pdf.js.
For Microsoft documents, you should use Apache POI on server side, and maybe convert it in an other format like csv or json to send it back to your js client

You can make use Jquery datatables tool, to enable export to PDF/ excel. I have used this in earlier project, works very well. It's best part is it is configurable.
http://www.datatables.net/

Related

How to add Header/Footer in Google Drive from Java API?

I converting HTML file to PDF via Google Drive Service. I want to add Header and Footer on pages. How can do that using Java Google Drive API?
PS: If there is not proper way than any workaround would be appreciated.
I don't think you can do this directly using Google Drive API. If you are fine with some workaround, I would use Google Apps Script FooterSection Class:
Upload file using Files.insert() with option convert=true
Either trigger or keep running script on specific folder which does the following:
Modify Footer using FooterSection Class
Export Google Document file as PDF
In order to export PDF, there are two ways I can think of.
Using Document Class of Apps script
doc.getAs("application/pdf")
Or getting export link of PDF from Google Drive API using Files.list() where you can get downloadable link for PDF.
"exportLinks": {
"application/pdf": "https://docs.google.com/feeds/download/spreadsheets/Export?key={FILE_KEY}&exportFormat=pdf",
"application/x-vnd.oasis.opendocument.spreadsheet": "https://docs.google.com/feeds/download/spreadsheets/Export?key={FILE_KEY}&exportFormat=ods",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "https://docs.google.com/feeds/download/spreadsheets/Export?key={FILE_KEY}&exportFormat=xlsx"
},

Java Web application, how to let a client save a generated .txt file?

I have a JSF Web application, and at some point i present the client a big chunk of information, I want to have a save as link, that allows the client to save this information on his computer as a .txt file.
Information on how to achieve this or a good tutorial would be great.
Does this work for you? You probably would need to set the ContentType to "application/octet-stream", otherwise the client's browser will display your text file instead of offering the option to "Save as".
I believe your best bet may be to have that link actually generate an Ajax call to generate the text file and set it as the src attribute of an iframe on the page. That will trigger (I think) the file download box.

how to convert a HTML web page into a PDF file using Java

i've been searching on the internet on how to convert a HTML page into a PDF file using Java. i found a lot of pointers, and in short, they don't work or are too difficult to implement. i also downloaded a commercial product, pdf4ml; the API is something i'd be happy to work with, except that when i crawled a simple page on wikipedia, i get a out of memory error (setting Xmx to 1024 M). in some approaches, they suggest converting HTML -> XHTML -> FO -> PDF. however, i am getting a lot of exceptions for the XHTML-to-FO XLS file; and reading the documentations, it's not something that i have enough time to understand right now.
here are my questions/concerns.
1. is there another cohesive API out there that will easily convert HTML to PDF (commercial or not)?
2. is there a way i can simply capture a HTML page and store it as a single file. this approach would be similar to using internet explorer's way of saving a web page as a web archive (single file, MHT format)?
any help is appreciated. (btw, i know this question has been asked repeatedly, but in addition to the original spirit of the question, i'm opened to other ways). thanks.
Try wkhtmltopdf, which is using WebKit. Another option (I'm using that currently) is using OpenOffice (remote controlled via macros).
you may use iText open source Java lib for that, and read this
or use YaHPConverter open source Java lib.
or do this whith help of icepdf popular open source lib
or use pd4ml, but it not free, only trial.
or use this, and this is man for it.
My 2 cents using opensource tools:
You can use either Capture screenshots with Selenium or WebDriver to save html page's screenshot in an image file from your Java code. And once you have image file you can convert it to pdf again from your Java code.
EDIT:
It seems you can do all that in 1 step using itext Html to Pdf
I am not sure but you could Try
1) cobra html rendering engine http://lobobrowser.org/cobra.jsp
2) htmleditorkit -- part of jdk
3) JWebPane
Use the rendering kit to parse and render html. The rendered out put is a swing component. Swing component can be used by itext to generate pdf file out put
You can try out Pdfcrowd. It is an easy to use commercial online API with many options and with support for Java.
It can create PDF either from web pages or raw HTML code.

How to show the printable document directly in acrobat with out saving?

I am using PD4ML to print a PDF file and It is working fine. Now the thing is I want show that file directly in acrobat with out save that file. In Local version I am using
Program.launch(getFilePath());
It is working fine but in web version I am unable to get that.
Can you please suggest me, Its very helpful.
Thanks,
Vara Kumar PJD
The web isn't like your desktop, so forget about doing things on the web the way you do them on the desktop without at least some effort.
Know that you don't read PDF files on the web using Acrobat without a browser plugin. Or some other reader like Foxit Reader.
My recommendation: forget about doing it this way. Either server your pdf as a file that can be downloaded, or read this SO post about embedding PDF in HTML.
I don't think this will be possible: "showing file outside browser in an application without user consent" because that is how browser are made for security reason. The best you can do is, as pointed in earlier post is by darioo, to show file in browser or prompt user to download/open.

DataGrid In Java Struts Web Application

After scouring the web I have edited my question from the one below to what it is now.
Ok I seem to understand that I don't need all the capabilities of excel right now. I think i am satisfied having a data grid to display data. Basically i am working on Struts 2 and I wat my jsp page to have an excel like feel and hence looks like even a datagrid is sufficient. I came across This Technology
I am not sure whether I must go ahead and use it. Any other suggestions, alternatives are welcome
The older version of the question
"I have a java web application running on windows currently. I may host it in future in a Linux Server.
My application allows people to upload data. I want to display the data they have uploaded in an excel file and render it in a portion of my webpage.
How do I go about this ?"
Basically you would need to read the excel files, get the data in some kind of java objects, and then show it back to user as a normal HTML page with tables etc..
If you want to show the excel files in such a way that your users are also able to edit these then you need to look into javascript / ajax to make a UI as per your needs.
An easy and open source way of reading the uploaded excel files in java is via Apache POI. It is capable of reading .xls files as well as the newer OOXML .xlsx files.
http://poi.apache.org/spreadsheet/
They have very helpful examples which can get you started within 10 minutes..
http://poi.apache.org/spreadsheet/quick-guide.html
If you can allow data to go to another site, then you can use ZOHO. Their online Excel Editing is reasonably good and you don't really have to do anything much.
Maybe you can try http://www.jxcell.net:
It is a java spreadsheet component which allow you to edit your Excel via web page.

Categories