SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Export to .doc or pdf

    Hey guys -

    I have a page with many CSS elements that I would like to add some functionality to. I would like to provide the option for the user to print the page, as well as export the page as a pdf or .doc. The page presents data from a database in both list and table form.

    Any tips? Thanks for your time

  2. #2
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've done this a few times ( Mostly from php! ) , they are tons of stuff on the net on how to do it,

    Just to start you off ( i cannot post links so just search google for the following ) :

    Pdf: PDF::Writer for Ruby
    Doc: ruby-doc

    Get reading

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lulz thanks d00d

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the "print page" option, the best policy is to use a dedicated print CSS. You can call more than one style sheet in your HTML header. If you have two and one has the "media" attribute set to 'print', that one will be used when printing and the other in normal viewing. Rails gives you the tools to do that easily:
    Code:
      <&#37;= stylesheet_link_tag 'standard_style_sheet' %>
      <%= stylesheet_link_tag 'print_style_sheet', :media => "print" %>
    Put that in a the header of a layout and the 'standard_style_sheet' css file will be used for screen, and 'print_style_sheet' when printing. Of course you'd rename those to match the controller name in line with normal Rails conventions.

    It's then worth adding no_print and print_only class definitions to your style sheets.

    In 'print_style_sheet' you'd do something like this
    Code:
    .no_print {
    	display: none; 
    }
    .print_only {
    	/* Display print_only elements */
    }
    And reverse it in the 'standard_style_sheet'.
    Code:
    .no_print {
            /* Display no_print elements */
    }
    .print_only {
    	display: none;	
    }
    Note that in HTML, class="one two" equates to 'this element belongs to the class "one" AND the class "two". Class names separated by spaces act as a list of classes the element belongs to. So changing an element's class definition from class="navigation" to class="navigation no_print" means it will continue to be modified by CSS directives set against .navigation, but now it will also be modified by directives set against .no_print.

    You can then choose which HTML elements to have in each view. For example you may want to hide navigation links in the print view and give someone a sign off box to add a signature to the print out:
    Code:
    <a href="#bottom" class="no_print">Go to bottom</a>
    <p>A bit of text that will appear in both screen and print fomats</p>
    <div class="print_only">
      <p>Please sign here:</p>
      <p>__________</p>
    </div>
    Also:
    Code:
    <% link_to_function("Print Page", "javascript:print()") %>
    Will give you a print link. However, for most occasions users can simply use the normal browser print options. That's all that piece of JavaScript is calling. It not doing anything particularly special.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't expect THAT much help... thanks so much!!

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Location
    West Palm Beach, FL
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been looking at this too, as I'll probably have to provide both formats. While you can create a PDF document that way, I don't think you can convert an HTML document with CSS into a PDF document in Ruby at all. Not with decent CSS support anyways. It looks like I'm going to have to use something from another language. Depending on the type of CSS support you'll need (very good or poor), it could be tricky.
    www.Bidsketch.com -- Proposal software for designers.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •