aspose file tools*
The moose likes JSP and the fly likes Printing a JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Printing a JSP page" Watch "Printing a JSP page" New topic
Author

Printing a JSP page

Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Hi friends,
i am developing an web application where customers and vendors can able to view a detailed report of what are all the product they purchase/sold. Here i need to print that report and not the whole page.. I think i am clear my point. Please help me do accomplish this.. I don't want my whole site design to be printed, instead print that particular table that contains the report... Thanks in advance. Waiting for reply from ranchers.... :roll:


Never try to be a hard-worker. Be a smart-worker.
My Blog
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42601
    
  65
The usual way to accomplish that is to provide a "Print" link/button that opens a window containing just the parts you want to print. If you want to get fancy then that window could call the JavaScript print function in its onLoad handler, so that the user doesn't need to select the print menu.


Ping & DNS - my free Android networking tools app
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16233
    
  21

There are 2 options here, at least.

One is to print the displayed page, the other is to create a formatted report.

CSS has the wonderful capability that you can define styles that only take effect in certain environments, such as on a printed page. Quite a few sites take advantage of that these days. Some of them include the print styles as part of the basic page display. In this case, for example, you do things like specify a style that suppresses the page framing (menu sidebars, for example). By doing that, you eliminate the need for a separate "print this page" function - and a trip back to the server for a print-friendly page layout.

For things with more precise layouts, it's sometimes better to generate a true ready-for-print report, such as a PDF. There are a number of ways to do this in Java, either using PDF-creation libraries or XSL-FO (for example, Apache FOP).


Customer surveys are for companies who didn't pay proper attention to begin with.
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Originally posted by Tim Holloway:
There are 2 options here, at least.

One is to print the displayed page, the other is to create a formatted report.

CSS has the wonderful capability that you can define styles that only take effect in certain environments, such as on a printed page. Quite a few sites take advantage of that these days. Some of them include the print styles as part of the basic page display. In this case, for example, you do things like specify a style that suppresses the page framing (menu sidebars, for example). By doing that, you eliminate the need for a separate "print this page" function - and a trip back to the server for a print-friendly page layout.

For things with more precise layouts, it's sometimes better to generate a true ready-for-print report, such as a PDF. There are a number of ways to do this in Java, either using PDF-creation libraries or XSL-FO (for example, Apache FOP).




Sorry.. i ain't heard that before.. Its very helpful if you post some codes or steps involved there.. Please forgive me if this question is rubbish..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42601
    
  65
Its very helpful if you post some codes or steps involved there.

This is what Tim's talking about, and I second that this approach is preferable to the one I mentioned.
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Thanks for the link Ulf.. The problem is i have a logo image with medium resolution on top of my page and i don't want it to be printed when i print the data that i need... How could i achieve this?.. When i put display:none its not even displayed in the page... Thanks in advance...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42601
    
  65
Did you read the article? You'd have two stylesheets, one for display that shows the image, and one for printing which hides the image.
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Yes i do... Now i got it... The search box i embed within the picture is still shown up in the print preview.. So i try to make it invisible... ... I'd get my hands off that as soon as i get finished with that...
jose raja
Greenhorn

Joined: Feb 08, 2009
Posts: 5
hi,

i am just trying to print the page as pdf using print preview function using itext. i couldn't get the page as it is. it is shrinked into two pages instea of one page. anyone help me?
jose raja
Greenhorn

Joined: Feb 08, 2009
Posts: 5
hi friends,


I want to change my SVN username and password. What are the steps to be followed to change my svn username and password.

Anyone please!!!

Thanks in advance.

jose raja
Greenhorn

Joined: Feb 08, 2009
Posts: 5
Hi,

I want to convert the html content into the pdf format.

How can i do this.

Here is my code that converts only the text items into the pdf and it omitted all the textboxes, textareas, checkboxes.....

import java.io.FileOutputStream;
import java.io.FileReader;
import java.util.ArrayList;

import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.html.simpleparser.HTMLWorker;
import com.lowagie.text.html.simpleparser.StyleSheet;
import com.lowagie.text.pdf.PdfWriter;

public class generatePdf {
public static void main(String[] args) throws Exception {
Document document = new Document();
StyleSheet st = new StyleSheet();
st.loadTagStyle("body", "leading", "16,0");
PdfWriter.getInstance(document, new FileOutputStream("c:/MissedVisit.pdf"));
document.open();
ArrayList p = HTMLWorker.parseToList(new FileReader("c:/MissedVisit.html"), st);
for (int k = 0; k < p.size(); ++k)
document.add((Element) p.get(k));
document.close();
System.out.println("Pdf Generated!");
}
}

Any pointers to this to get all the contents that are in Html.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing a JSP page