function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Arun BalaArun Bala 

ShowHeader="true" ... page print .. issue

Hello folks,
Today  I am challenged with this problem .. I have my page's showHeader attribute set to true as I wanted to display the sideBar & the header .. at the same time, while printing the page using JS window.print(), my side bar and the header also get printed .. but I wanted only the VF tab(page) to be printed.

Any hints folks ? your help with be greatly appreciated !


Thanks
A B


Message Edited by Arun Bala on 12-23-2008 10:40 AM
Arun BalaArun Bala
Any takers ??
kyleRochekyleRoche
Tie the value to a variable.
showHeader="{!showHeaderVar}"

Then you can tie it to a POST param or something... like /apex/page?printView=true
Sam.arjSam.arj

Try using property definition for showHeader  attribute of the Page tag.

Code:
<apex:page showHeader="{!headerVisible}" action="{!init}">

 
Then make property headerVisible sensitive to what is passed in via URL parameters:

Code:
public class controller()
{
  public boolean headerVisible
  {
    get;
    set;
  } 
  public PageReference init()
  {
     string hv = ApexPages.currentPage().getParameters().get('printMode');
     headerVisible = (hv == 'true');
  }
}

 Then you can use a link or button view the same page in a pop window with javascript window.print added as well.



Arun BalaArun Bala
Hi kyleRoche, Sam.arj
Thanks a ton for your responses.

I am hitting a road block again. Now when I use a property for showHeader and then on click of the print button if I reload the page, I lose all the unsaved data on the page. The unsaved data should also be printable ...

Did my point make sense ?


Message Edited by Arun Bala on 12-23-2008 03:09 PM
kyleRochekyleRoche
i would put a quick save (at least save the temp data to a custom object) in the print method... do the save before you send back the new pagereference...
Arun BalaArun Bala
Oops .. I need to store a lot of data temporarily then ...  because I am going to invoke the page fresh again and then I need all the data ... I wish there was an easy solution to the problem ...

I guess developers need to be given better control over the showHeader attribute.


Message Edited by Arun Bala on 12-23-2008 07:04 PM
dchasmandchasman
Take a look a this example I put together - handles the HTTP POST including maintaining viewstate and any controller transient data without requiring you to store anything anywhere. My example c:printMe component also opens a separate print preview window and manages print view state automatically. One of the very powerful techniques you can leverage in a custom component is value binding via expression passing to create components that can modify values in the calling page's controller/state/etc.

Code /apex/printDemo:

<apex:page controller="PrintDemo" showHeader="{! !print}">
    <h1>PrintDemo [{!created}]</h1><br/>
    <em>Printing view: {!print}</em><br/>
   
    <apex:form id="theForm">
        <c:printMe value="{!print}"/>       
    </apex:form>
</apex:page>

public class PrintDemo {
    public PrintDemo() {
        created = System.now();
    }
   
    public DateTime created { get; private set; }
   
    public boolean print { get; set; }
}

 and here is c:printMe:

Code /apexcomponent/printMe:
<apex:component>
    <apex:attribute name="value" type="Boolean" description="TODO: Describe me"/>
    
    <apex:outputPanel rendered="{! !value}">
        <apex:inputHidden id="printView" value="{!value}"/>
        
        <script>
        function printMe() {                
            var printViewInput = document.getElementById('{!$Component.printView}');
            var form = printViewInput.form;
    
            form.target = 'printWindow';
            printViewInput.value = true;
            
            var printWindow = window.open('_blank', 'printWindow', 'menubar=1,resizable=1,width=600,height=800');
            form.submit();
        }
        </script>
        <apex:outputLink onclick="printMe(); return false">Print Me</apex:outputLink>
    </apex:outputPanel>
    
    <apex:outputPanel rendered="{!value}">
        <script>
        window.print();
        window.close();
        </script>
    </apex:outputPanel>
</apex:component>

 




Message Edited by dchasman on 12-27-2008 05:35 PM
Arun BalaArun Bala
Hi Doug,
Thanks for your detailed response. This approach is awesome except that one of my scenario is not getting covered if I use this approach. i.e., I have a pageBlockTable and inside that I have styles of certain panelGrids set to display:none on page load. On performing some action X on the page, the style of the panelGrids  will be changed ti display:block. But when the form is printing after performing the above mentioned action X , the form is still getting posted with the default style, i.e., display:none and hence these panelGrids are not getting printed. Any advise Doug ?


Thanks.
dchasmandchasman
I would add in formula logic where you are setting the style to display:none or display:block server side that is also controlled by the print property in your controller or extension - just about anything in your markup/attributes/etc can be generated by an inlined formula expression... You could also handle this in a more client side way using javascript to read a variable generated server side that just contains the value of the print property like this:

Code:
<script>
var displayForPrinting = {!print};

// Call you javascript that sets the display value here
</script>

An approach I like to use for dynamically controlling visibility client side of a group of elements is to tag them with a specific style that I can then use style manipulation to change everything as a set instantly - see this post for a concrete example of this.

Arun BalaArun Bala
Hi Doug,
Thanks again for your response. I moved the logic for displaying the styles to the extension class and made a work around.

I sincerely appreciate your thoughts and help on this issue. Visualforce rocks :-)


Thanks.