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
J KeenerJ Keener 

Questions regarding Printing a Visualforce Page

I'm in the process of converting an s-control to a Visualforce page, and the only stumbling block I've ran into is sending the page to the printer.

As a background, in the s-control, I had added the following code to the top and bottom of the s-control to provide "Print Screen" buttons that allowed for printing.

Code:
     <form name="PrintInformationTop">
        <input type="button" name="PrintInformationTop" value=" Print Screen " onClick = "window.print()">
     </form>

 The above code worked nicely by bringing up the standard print dialog and the output generated nicely.  In addition, it only printed the s-control frame and did not print the top tabs nor the sidebar.

When I placed the above code into Visualforce page, it continues to work, but it does not exclude the top tabs and the sidebar.  I'm assuming visualforce pages are not rendering in the same sort of a frame as s-controls did.

In addition, as you can see in the screenshots below, I've got a bit of basic formatting to do on the visualforce pages so that they print nicely with grids, etc. 

My initial question is what is the best way to print a Visualforce page to exclude the top bar and the side bar?

Secondly, for the formatting, based on what I found on the discussion boards, I was considering using "media" stylesheets to try to cleanup the look and feel for printing.  Visually on the page, the Visualforce page looks great, but when printed without gridlines, it doesn't read as well as the old s-control page.  Below is a snippet of what I found elsewhere in the discussion forum that I was going to try and use?  Does this seem to be the best approach to doing this?

Code:
style type="text/css" media="print">
...
</style>

 
I did review the solutions regarding displaying a Visualforce page as a PDF, and although I like that functionality, I don't know if it would help in this instance.  When I display this page, It contains a lot of historical actiivities.  By default the descriptions for these activities are hidden, but "Show"/"Hide" functionality exists so that a user can unhide the descriptions they want to print prior to printing.  What I can tell about the PDF functionality, it redraws the Visualforce page from scratch, so if I used some of the current methods discussed, if I had the button generate a PDF version, it would be a brand new page of the Visualforce page, not one where the user has made a number of changes upon.  If I'm incorrect on this one, let me know, because this would be a nice way of handling it.  (I know when calling the PDF version of the page, I could try to pass parameters, but this would get pretty complex with hundreds of activities...)

Thanks for any ideas!

Jon Keener
jhkeener@ashland.com






Ron HessRon Hess
take a look at this article
http://wiki.apexdevnet.com/index.php/Visualforce_CaseHistoryTimeline

shows how to build a print optimized page
see CaseHistoryPring

you can also change
 renderAs="pdf">

to
renderAs="html">

and see how that looks


excluding the top and side bar is done with
showHeader="false"



DS777DS777
Hi Ron,

How to handle pagination in PDF ? i.e printing the headers and footers.
It looks like when using the datatable the
class cannot be set .

any examples would be quite helpful. I have tried using W3C page rules but with not much sucess.
Ron HessRon Hess
the case history example has pdf examples, with pagination.
i think i saw someone report that flowing div's into the header and footer is not yet supported.

something like this in a style tag
Code:
@page {
 
 /* Landscape orientation */
 size:landscape;
 
 /* Put page numbers in the top right corner of each
    page in the pdf document. */
 @top-right {
  content: "Page " counter(page);
 }
}


 

gireeshzgireeshz
Yes, in my testing Ron is correct.  the headers and footers using the @page stuff works, but apparently you cannot flow div's into the 'content' parameter.  the only thing that I have gotten to work is plain text, although the w3c spec states you should also be able to use a URL and/or and image, so that might help a bit.  I haven't tried that out yet tho.
JeremyKraybillJeremyKraybill
I know this is an old thread, but since it was one of the few pages that came up when I searched for PDF pagination, and I couldn't find a solution on this board that solved my needs, I thought I would post a link the solution I came up with here.

We needed to do pagination based on a variable number of fixed-height page sections. Here's the link to the solution I came up with. It's not ideal, but it works. Hope this helps someone looking for the solution like I was.

Jeremy Kraybill
Austin, TX
Arun BalaArun Bala
Hi Ron,
I just came across this post .. I am also facing the same issue that J Keener had faced. I saw your response :
excluding the top and side bar is done with 
showHeader="false"

But I wanted to exclude the top & side bar only while printing. Any hints on this would be helpful Ron.


Thanks.
dchasmandchasman
I suspect this post will be of use in your quest to print...