File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes printing a form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "printing a form" Watch "printing a form" New topic
Author

printing a form

Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
hello.

i'm kinda new at this and i would just like to ask how print.
i have a form in my browser and I would just like to kind of like export that to microsoft word for printing.

how is that done?

thanks
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

Printing is not a simple feat when it comes to web programming of any kind. The most common way people print, is just to use built-in printing that prints the generated html such as right-clicking in IE and selecting 'Print'.

You can print via Word/PDF format but you first have to convert the input data into one of these files, then let the user download it. There's no guarentee after the user has downloaded that they will print the data, though. There are a number of plugins (free?) that support document conversion.

My suggestion is when you want to print the data create a report-like HTML page that opens in a new browser window and displays the data neatly on the screen (without web page menu bars for example). Then, the user can just print that page.


My Blog: Down Home Country Coding with Scott Selikoff
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
yes, i thought of that but its really difficult to format the data especially if its a table and some other stuff.

can't i like export the generated data to word or something? because i need to generate printable reports.

thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

For printing, the best format would be PDF. You could allow your users to download PDF versions of your reports. There are free PDF Java API's out there. You might want to check out the Other Open Source Projects forum for suggestions.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
Originally posted by shuini gustav:
yes, i thought of that but its really difficult to format the data especially if its a table and some other stuff.

can't i like export the generated data to word or something? because i need to generate printable reports.

thanks


HTML output is hell on paper. Page breaks never quite work well.

Check out JasperReports
http://jasperreports.sourceforge.net/

Now something I'm looking into is printing directly from the tomcat server (intranet wise) to a shared printer. Any ideas?
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
i have no idea how to do that

it's just really difficult to try and print my form directly from the browser, it can't be formatted properly.

i googled for free java pdf api's and here's some of what i got.
can anyone tell me which of these is the best to use? i haven't had any experience from any of them. like, which one is the easiest to use and make a program of?

Big Faceless Java PDF Library(this is commercial though)
iText
Orinoco
Smart JPrint

can anyone else suggest anything? it has to be free of course.

thanks a lot
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
I have a friend who used iText. He used it to do exactly that print PDFs. Actually generate them. The printing came from the browser as it opened the PDF.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

Originally posted by Gerardo Tasistro:
HTML output is hell on paper. Page breaks never quite work well.

Not if your HTML is structured well enough.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

Originally posted by Scott Selikoff:

Not if your HTML is structured well enough.


Care to share your insights on this?
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
Originally posted by Scott Selikoff:

Not if your HTML is structured well enough.


And meets some limitations and is read always on the same browser and printed on the same type of paper. For everything else there is PDF.
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
i always have a hard time printing tables directly from html. it doesn't fit on one paper and you can't control the fonts and margins.

thanks. i'll try iText. hope it's eaasy to use though
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

Originally posted by Bear Bibeault:


Care to share your insights on this?

Depends what your developing on it. One of the best tests is knowing how well your page will shrink and grow based on the browser size. If you page displays nicely on 800x600 as well as 1600x1200, then printing shouldnt be too much of atrouble. Also, focus more on text formats than graphical images. Take a page from other websites that do this alot like mapquest and travel sites. They often can print out pages that look exactly like their web pages.
[ February 03, 2006: Message edited by: Scott Selikoff ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: printing a form
 
Similar Threads
Printing using javascript
Help about awt.print
Pring API suggestion needed
Prepared Statement - printing out the statement
Is any way We can tell JSF to not response