Forums

Home » Liferay Portal » English » Liferay Legacy

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Nigel Elliott
Printing a portlets contents.
March 14, 2007 9:24 AM
Answer

Nigel Elliott

Rank: Junior Member

Posts: 67

Join Date: August 3, 2006

Recent Posts

Hi Guys,

I am inquiring to see if anyone has successfully implemented the portlet-mode of print.

I have a need to print the contents of one of my portlets.

I know that the print mode is a custom section in the jsr-168.

If anyone has done this I would greatly appreciate some advice/help on the issue.

Regards,

Nigel.
Richard Gregory
RE: Printing a portlets contents.
March 16, 2007 8:24 AM
Answer

Richard Gregory

Rank: Junior Member

Posts: 34

Join Date: February 5, 2007

Recent Posts

I managed to add a print mode to my portlet (with Liferay 4.2.1, I never tried with 4.1.x), although I'm still after some help.

I extended com.liferay.portlet.LiferayPortlet, rather than GenericPortlet, added a doPrint(RenderRequest, RenderResponse) method to to my portlet, and added <portlet-mode>print</portlet-mode> to the portlet.xml, and this gave me a print mode. The other thing I did was to modify webapps/ROOT/html/common/themes/portlet.jsp to set the window state to maximised when the url for the print mode is generated. Hope that helps you.

This is where I'm looking for some help from anyone who has implemented a print mode.

At the moment I have a javascript in the jsp that generates the content of my print mode that calls the window.print(); command to open the browser's print dialog automatically for the user. This works, but will print the whole portal window, when what I really want is just print the content of the particular portlet.

I tried wrapping my content in a
1<frameset><frame name="printFrame"></frame><frame>
, as with javascript I should be able to directly access and print the frame by name, but this doesn't seem to work, and when I tried to use javascript to display an alert with the number of frames in my window as a test it says '0'. I also tried to add onload attributes to the frame and frameset elements, but these seem to be ignored as well, so i guess that when my frameset is wrapped in the rest of the portal content that the frameset becomes invisible to the browser (although I can see it in the page source.

If anyone has any suggestions about how to print the content of a single portlet, rather that the whole portal page I'd be very grateful.

Richard.
Nigel Elliott
RE: Printing a portlets contents.
March 16, 2007 7:22 AM
Answer

Nigel Elliott

Rank: Junior Member

Posts: 67

Join Date: August 3, 2006

Recent Posts

Hi Richard,

I have successfully managed to print the contents of a portlet screen only by using css.

By using the 'media=print' option in css.

Then you can basically say that on print the body is hidden except for the parts you need by defining a css style to do so.

Would that be of any help?

If so I can give an example of mine?

Is maybe not ideal but it works....
Richard Gregory
RE: Printing a portlets contents.
March 16, 2007 8:29 AM
Answer

Richard Gregory

Rank: Junior Member

Posts: 34

Join Date: February 5, 2007

Recent Posts

Hi Nigel,

Yeah, an example would be usefull. I've never tried using css media types.

Richard
Nigel Elliott
RE: Printing a portlets contents.
March 16, 2007 8:44 AM
Answer

Nigel Elliott

Rank: Junior Member

Posts: 67

Join Date: August 3, 2006

Recent Posts

No Problem.

I have included it all as one. But ideally should be in a separate css file.

The key option is the media="print"

 1<!-- CSS styling for printing -->
 2   
 3    <style type="text/css" media="print">
 4    <!--
 5   
 6    body {visibility:hidden;}
 7   
 8    .print {
 9    visibility:visible;
10    background-image: none;
11    background-color: #FFFFFF;
12    float: none;
13    margin: 0px;
14    padding: 0%;
15    width: auto;
16    position: relative;
17    top: -190px;
18    }
19   
20    .headers {
21        color: #0000FF;
22        font-weight: bold;
23    }
24   
25    -->
26    </style>


So as you can see from above is that when the print is selected (ie. I have a button on my portlet that says "Print" and that executes the javascipt "window.print()".

The body is hidden....

And anywhere that I have specified the class="print", (ie. on a table, paragraph) only those will print.

You can then also position the contents where you want.

I use
1position: relative; top: -190px;
to bring the first header back to the top of the screen.

And you can check to see if its working by using print preview.... it will only show the items you have selected with class="print" if its working correctly.

Let me know if you have any more questions?

There are a lot of examples of how this is done on searching through google.. i'm only beginning to look at this also..
Richard Gregory
RE: Printing a portlets contents.
March 19, 2007 2:40 AM
Answer

Richard Gregory

Rank: Junior Member

Posts: 34

Join Date: February 5, 2007

Recent Posts

Hi Nigel,

Thanks. For now I added the following to my css_cached.

1@media print {
2    body {visibility:hidden;}
3    
4    .print {
5    visibility:visible;
6    }
7}


and that seems to have the desired effect of only printing the portlet content.

The only problem I have now is that this will be universally applied. Do you know if there is a way to specify this in a seperate style sheet which is only used when the portlet is in print mode? I'd like to keep the option for users to be able to just print out all portlets as they are on their page in the view mode, or to go to print mode for an individual portlet and just get the content of that portlet.

Richard
sailaja prathi
RE: Printing a portlets contents.
December 18, 2008 10:07 PM
Answer

sailaja prathi

Rank: New Member

Posts: 12

Join Date: October 28, 2008

Recent Posts

Nigel Elliott:
No Problem.

I have included it all as one. But ideally should be in a separate css file.

The key option is the media="print"

 1<!-- CSS styling for printing -->
 2   
 3    <style type="text/css" media="print">
 4    <!--
 5   
 6    body {visibility:hidden;}
 7   
 8    .print {
 9    visibility:visible;
10    background-image: none;
11    background-color: #FFFFFF;
12    float: none;
13    margin: 0px;
14    padding: 0%;
15    width: auto;
16    position: relative;
17    top: -190px;
18    }
19   
20    .headers {
21        color: #0000FF;
22        font-weight: bold;
23    }
24   
25    -->
26    </style>


So as you can see from above is that when the print is selected (ie. I have a button on my portlet that says "Print" and that executes the javascipt "window.print()".

The body is hidden....

And anywhere that I have specified the class="print", (ie. on a table, paragraph) only those will print.

You can then also position the contents where you want.

I use
1position: relative; top: -190px;
to bring the first header back to the top of the screen.

And you can check to see if its working by using print preview.... it will only show the items you have selected with class="print" if its working correctly.

Let me know if you have any more questions?

There are a lot of examples of how this is done on searching through google.. i'm only beginning to look at this also..



Hi Nigel,
I would like to print some images presented on my struts portlet at liferay . Could you please guide me the way how to implement the print mode in liferay . As i am new to liferay i was using liferay from past two months. We are using liferay latest version if possible could you please explain it by an example so that i can work on it. Any help on this would be appreciated.

Thanks in Advance,
Sailaja ...
Gaurang Sheladia
RE: Printing a portlets contents.
March 5, 2011 7:47 PM
Answer

Gaurang Sheladia

Rank: Regular Member

Posts: 160

Join Date: February 15, 2009

Recent Posts

Hi Nigel,

I want to print only the content which is displaying in popup.

Can you please suggest any idea, how can i implement the print functionality in liferay popup?

Thanks in advance.

Thanks,
Gaurang
Abhishek Dhingra
RE: Printing a portlets contents.
October 11, 2012 2:47 AM
Answer

Abhishek Dhingra

Rank: Junior Member

Posts: 52

Join Date: April 7, 2011

Recent Posts

Hi,

I have a requirement where i need to print all my pages.
I tried the same way you have suggested, but in my case it is only printing the first page of the document. Please suggest, how i can print all my pages.

Thanks,
Abhishek