Fri 20 Apr 2007
How-To: Button for Printing a Standard PeopleSoft Page
Posted by ChiliJoe under PeopleSoft • PeopleTools • PIA • TutorialI’ve often receive requests for a solution regarding printing a PeopleSoft page by clicking a button. This tutorial presents a step-by-step instruction for the simple requirement of printing the current page.
Problem/Requirement Definition
Insert a button on a standard PeopleSoft page. Clicking this button will print the current page. The button itself, the pagebar (the portion containing the New Window and Help links), and the action toolbar will not be included in the printout.
Solution
Step 1. Choose a field from a derived record which you’ll use as the field for your pushbutton control. It should be in MixedCase format and at least 25 characters long. I recommend creating a new field for this purpose, so that you can assign a suitable label to the field.
Step 2. Insert the pushbutton on your page. Set the Destination to External Link and type is Dynamic. For this tutorial, I’ve created the field JS_PRINT and attached it to the DERIVED_WORK record. This is the field that the pushbutton is assigned to.
Step 3. Go to the General tab and fill in the Page Field Name. Enter the value PRINT_BTN.
Step 4. We assign a value to the external link pushbutton via PeopleCode. In the FieldDefault PeopleCode of DERIVED_WORK.JS_PRINT, put the following PeopleCode:
DERIVED_WORK.JS_PRINT = "javascript:window.print()";
This is the code that triggers the print command in the browser when the button is clicked.
Step 5. Insert an HTML area at level 0 of the target page. Set the Value to Constant and put the following text:
<style type="text/css">
@media print {
#PAGEBAR, .PSHEADERTOOLBARFRAME, #PRINT_BTN { display: none }
}
</style>
This CSS declaration tells the browser to omit the pagebar, the tool bar, and the print button from the printout.
Note: This tutorial assumes that the print button is placed at the level 0 of the page.
And there you have it!
Normally, I have reservations about inserting the CSS in the body of an HTML document. However, it is much simpler and appears to work in most browsers including IE6 and Firefox. This post presented a more elaborate technique.
Additional Requirement
Suppose it is desired that the Folder Tabs (top) and Hyperlinks (below) for page navigation should also be omitted on the printout.
Solution
This requirement is little more tricky since PeopleTools doesn’t assign an id or a class to these sections of the page. We would need assign a class to these elements via javascript. The following script adds the class of PS_PAGETABSNAV to the Folder Tabs and Hyperlinks; the style is updated to omit PS_PAGETABSNAV from the printout.
Caveat: This may not work on all 8.4x versions and may stop working in future versions of PeopleTools. This is tested only on 8.45
Modify the content of the HTML area for step 5 above.
<script type="text/javascript">
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
addLoadEvent(function() {
pg_tables = document.%FormName.getElementsByTagName('table');
for (var i1=0, el_tbl; el_tbl=pg_tables[i1]; i1++) {
if (el_tbl.className=='PSPAGECONTAINER') continue;
tds = el_tbl.getElementsByTagName('td');
for (var j=0, el_td; el_td=tds[j]; j++)
if (el_td.className=='PSACTIVETAB'||el_td.className=='PSHYPERLINK') {
if (el_tbl.className) el_tbl.className+=' PS_PAGETABSNAV';
else el_tbl.className='PS_PAGETABSNAV';
break;
}
}
});
</script>
<style type="text/css">
@media print {
#PAGEBAR, .PS_PAGETABSNAV, .PSHEADERTOOLBARFRAME, #PRINT_BTN { display: none }
}
</style>
April 28th, 2007 at 12:42 am
Thanks for this post!
I’ve taken and modified it a bit to use it with Monkeygrease so I can drop a “print” link (or button) on a page and use it like you do above.
Thanks again!
Derek
June 27th, 2007 at 1:25 pm
Excellent Guide.
I got a question for you. Will the Pushbuttons be assigned the same class too or will they be different from the hyperlinks?
Again, your tutorials rock … :))
June 27th, 2007 at 1:50 pm
Manoj,
The push buttons are under the toolbar container having the class PSHEADERTOOLBARFRAME.
Does that answer your question?
June 27th, 2007 at 1:53 pm
Yes it does!! Thanks a ton!!
June 28th, 2007 at 6:38 pm
Hi,
I am using PT 8.45.18 and trying to print a page. But i am getting the URL of the page at the bottom and Component name at the top.
I tried above mentioned code. But, ‘PSACTIVETAB’ and ‘PSHYPERLINK’ classes are not loaded on page load. So, PS_PAGETABSNAV class is not assigned/appended to el_tbl.className.
Can you please suggest how to proceed?
Thanks,
Archi.
June 29th, 2007 at 12:17 am
Hi Archi,
Which peopletools version are you using?
Regarding the URL, I think that is generated by your browser. You’ll have to modify it from Page Setup menu item of your browser. For internet explorer, I think there is a way to script this. Google for it!
August 22nd, 2007 at 5:59 am
Hi,
First of all, let me thank you for your contribution. I am trying your suggestion, but apparently I am missing some security setup, Could you please help me, what is that required for priting. I am getting this error message.
You are not authorized to access this component. (40,20)
September 6th, 2007 at 3:15 pm
hi ,
excellent work!!!!!!!
I was just thinking how to print the page without having toolbars etc. and you just gave the idea……thanks!!!!
September 18th, 2007 at 11:05 pm
Your Tutorial rocks.
But I’m getting same error as other user here. Which says You are not authorized to access this component.
Can you please help
Thanks
September 19th, 2007 at 12:45 am
Hello,
I tried the solution but getting “You are not authorized to access this component. (40,20)”
Can someone please help. I cleared appserver cache and my browser cache and it didn’t work. Any help can be greatly appreciated.
Thank you!!
September 19th, 2007 at 3:29 am
My mistake. I didn’t follow the first step in your instructions. The field should should be in MixedCase format and at least 25 characters long. I was using a field with length 1. I created a new field as per instructions, set the default value to javascript:window.print()and it worked.
I can’t thank you enough for this wonderful article. Great job!
Thank you once again.
September 20th, 2007 at 3:43 am
Chad, Which work record did you use?
I have the field 25 char long mixed case. Still getting that error.
Thanks
November 6th, 2007 at 2:42 am
Excellent Write Up! Thanks for the tip. It works just what I expected.
November 6th, 2007 at 11:50 pm
Good piece of code. Exactly what i’m looking for.
I did steps 1-5 as you have mentioned. But When i click the Print Button on my page, i get this error:
Invalid or Missing Parameter in request.
Any suggestions??
Thnx,
Mia
November 7th, 2007 at 5:05 am
For some reason, If i put the code in Field Default (as you have mentioned), it didn’t work & gave me an error message - Invalid or Missing Parameter. Then, I moved the same line of code to page Activate & it worked. I did a trace & found that the field default was not fired at all. I’m not sure of the reason (trying to find out) but atleast found a way around to get this working..
Also, Any suggestions on exporting the contents of the page into Excel like sending it to a Printer?
November 16th, 2007 at 9:12 pm
Good idea…..
December 15th, 2007 at 7:51 am
Very nice …
January 26th, 2008 at 11:44 pm
This is awesome, but I need print preview rather than print. I’m just coming up to speed (barely) on javascript. I can’t get @media screen vs. @media print to work. I’m thinking I’ll have to open another window.
Anybody got any solutions or ideas? ANYTHING would be appreciated.
Thanks
January 29th, 2008 at 10:54 pm
@cher:
What you’re trying to do could be very tricky. One thing you may do is to perform stylesheet switching via javascript. Try googling for “javascript stylesheet switcher” as there are a lot of javascript solutions already out there. I think you’ll still need a deeper understanding of javascript and css to tailor them for your needs.
February 1st, 2008 at 9:44 am
Hi,
I am using PT8.42. I tried appending these codes ”
@media print {
#PAGEBAR, .PSHEADERTOOLBARFRAME, #PRINT_BTN { display: none }
}
” in my HTML. but, it didn’t work.
What’s the PS class name for New Window and Help hyperlink. Or is it because of PT version?
Thanks,
Choe
March 3rd, 2008 at 8:46 pm
Hi,
May i know how to print a resume from a component……….. I m doin a project on Resume Repository System…..
Or any idea abt this project……
May 3rd, 2008 at 4:57 am
The blog is superb!!!! it helped a lot…thanx chillijoe…
May 13th, 2008 at 4:56 am
Thanks for this posting ;-)
July 2nd, 2008 at 6:02 pm
How can we print the output in .pdf format rather than .htm ?
July 15th, 2008 at 5:24 am
Hi ,
This code works fine though.
i ahve a problem.The page isn’t printing fully the left margin is cutoff a bit.Can you please help me with this?
July 15th, 2008 at 5:36 pm
My program has created a pdf file and stored in temp folder. when I access a page, when I click print push button, how can I print that pdf file?
July 18th, 2008 at 4:35 pm
Hi,
I have a requirement that i have to print PDF file by clicking on a hyperlink.There are multiple no of Pdf files. i need a function in which i give the path of that file & it will print it.