Skip to main content
February 26, 2009
Question

Output to pdf

  • February 26, 2009
  • 5 replies
  • 723 views
Hola.

I have a .cfm page that is heavily marked up with css. It looks exactly the way the customer wants it but now they want to output that exact page into a pdf file. I know cfdocument/pdf doesn't do so well with css and that's true in this case. It outputs the document but it looks terrible.

Is there a better way to do this so I can output to pdf and have it look exactly the way the .cfm page does on the browser screen before going through the cfdocument transformation to pdf?

Can I output a page as an image?

Any assistance would be greatly appreciated.
    This topic has been closed for replies.

    5 replies

    February 27, 2009
    I was worried that may be the case. The document was first created in Excel and then saved as an html page.

    Oh well... I think I may have to start from scratch without styles.
    Inspiring
    February 26, 2009
    EnergyFed wrote:
    > I've found that CSS works quite well in a PDF file. However in order to make
    > it output correctly, you have to put CSS inside all of the <cfdocumentitem>
    > tags on the page. Otherwise if you just add the CSS in the top part of the
    > <cfdocument format="pdf">, CF seems to be selective on which styles it wants to
    > apply.
    >

    A lot of CSS works in the manner you want, if you are just styling text,
    font and color type properties.

    Things can start to get funky when you start to style, position and
    display type properties. Some of these don't make a lot of sense in
    relation to printing, but they may be integral to what makes a web page
    what it is when displayed on the screen.

    February 26, 2009
    I'll try cfdocumentitem and see how that works.

    The styles are attached in case you were curious.
    Inspiring
    February 26, 2009
    I've found that CSS works quite well in a PDF file. However in order to make it output correctly, you have to put CSS inside all of the <cfdocumentitem> tags on the page. Otherwise if you just add the CSS in the top part of the <cfdocument format="pdf">, CF seems to be selective on which styles it wants to apply.
    Inspiring
    February 26, 2009
    There are tricks to make cfdocument work a bit better with some CSS but
    it is probably not going to be perfect if you have complex styling going on.

    I am going to answer your question with a question of my own. Does your
    CSS heavy web page look exactly the same in every browser currently on
    the market including all past versions of them?

    The point of that question, is that when users request something like "I
    want a printout of this page to look exactly like it is on the screen."
    Their assumption is how it looks on their screen is how it looks on
    everybody's screen. As developers we should know that is not true. Web
    pages can look radically different based on what browser, computer,
    operating system and monitor combination it is viewed with. Throw in
    printers and printer drivers into that mix just makes an even larger
    astronomical number of possible combinations.

    To finally advise you on your original question. If a user wants a
    print out of exactly what they are looking at, the best source is a tool
    that uses their browser rendering engine and spits it out to their
    printer. For my Firefox browser I found this to be a very capable tool
    for doing just that: Screengrab
    https://addons.mozilla.org/en-US/firefox/addon/1146.
    February 26, 2009
    <cfdocument format="pdf">


    all style works inside <cfdocument format="pdf">