Hi folks:

Wondering if anyone had a solution for the following:

I found a nice php script (printit.php) to print out printer-friendly versions of our web site pages.

The link on our html pages to print out these pages is <a href="printit.php">Printer Friendly Page"</a>

This works fine, but we would also like to use the <link> tag so that when printing directly from the browser, the clean php page is automatically printed.

We tried doing this using the html <link> tag:

<link rel="alternate" media="print" href="printit.php">

But it only prints out a blank page. If I replace the php page value with any html page they print fine using this command.

Are we missing an attribute in the <link> tag which is causing the php page not to print?
Or is there another html tag to accomplish this?

Any help would be appreciated,

CJ
info@summationtechnology.com

    hmmmm.....

    that is odd, so you are telling us if you do

    <link rel="alternate" media="print" href="printit.html">

    it works fine, but if you do

    <link rel="alternate" media="print" href="printit.php">

    it doesn't

      you may be able to use a javascript solution somehow to suit your needs

      you can use window.print(); somehow, don't know if it will work in your situation

        Originally posted by stolzyboy
        hmmmm.....

        that is odd, so you are telling us if you do

        <link rel="alternate" media="print" href="printit.html">

        it works fine, but if you do

        <link rel="alternate" media="print" href="printit.php">

        it doesn't

        Actually it works fine with the following:

        <link rel="alternate" media="print" href="anyhtmlpage.html">

        There is no printit.htm.

        It does not work with a page that has the .php extension.

        Since the php page is calling a dynamically altered html page there may need to be special command I need to put in the link tag?

          hmmmm, that could pose some problems, i just want some more clarification if i could

          you will have

          link one //to print printer friendly page

          and

          link two //to print normal page

          i guess my small mind isn't following you too well

          is there a link i can get to without too much hassle

            Originally posted by stolzyboy
            hmmmm, that could pose some problems, i just want some more clarification if i could

            you will have

            link one //to print printer friendly page

            and

            link two //to print normal page

            i guess my small mind isn't following you too well

            is there a link i can get to without too much hassle

            Sorry I should of clarified this a bit better...

            there are 2 ways to print the page:

            1) From an url on the page: <a href="printit.php>print firendly page</a>
            This actually opens up the current html page, but stripped of all graphics by the printit.php script. You can then print this page.

            2) Print command from the browser. This is the reason for using the <link> tag with the "print" variable. The problem is this tag does not like to print the .php page

            Does this make sense?

            CJ

              aaahhhhh, yes it does not click in my mind now, unfortunately i am not sure how to help you, maybe someone with a little more client side scripting experience will be able to help

              sorry and good luck

                Could you post the file? It should, in theory, work, however if it's using something like $_SERVER['HTTP_REFERER'] to get the page to make printer-friendly, the <link> tag wont work. May be able to fix it up without too much effort 🙂

                  Originally posted by matt_4013
                  Could you post the file? It should, in theory, work, however if it's using something like $_SERVER['HTTP_REFERER'] to get the page to make printer-friendly, the <link> tag wont work. May be able to fix it up without too much effort 🙂

                  Please take a look and see if you can figure this out...

                  Here is a test page on our site:

                  www.suumationtechnology.com/5400_test.html

                  Here is the php script called printit.php:

                  <?
                  header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                  header("Last-Modifieed: ". gmdate("D, d M Y H:i:s"). " GMT");
                  header("Cache-Control: no-cache, must-revalidate");
                  header("Cache-Control: post-check=0,pre-check=0");
                  header("Cache-Control: max-age=0");
                  header("Pragma: no-cache");
                  /
                  || Takes the referrer document, only prints the content
                  || works only with documents on the same server. good enough :-)
                  || V.Satheesh Babu (vsbabu-removethis@vsbabu.org).
                  ||
                  || I put an HTML comment called "document_starts_here" before
                  || content starts and another one "document_ends_here" after
                  || the content. If you have been following some standard like
                  || that, it could be useful.
                  ||
                  || Installation instructions
                  || 1. Copy paste the code here to your favourite editor, and save it as some php3 file
                  || 2. The file name doesn't matter. I call it printit.php3
                  || 3. From your other web pages make a link to printit.php3
                  || 4. Test it out by clicking on the links in those pages
                  ||
                  /
                  if ($HTTP_REFERER)
                  $myURL = $HTTP_REFERER;
                  else
                  $myURL = "http://vsbabu.csoft.net/";

                  // here is the starting comment for your content
                  $START_CONT="document_starts_here";
                  // here is the ending comment for your content
                  $END_CONT = "document_ends_here";

                  $parsed_url = parse_url($myURL);
                  $myServer = $parsed_url['host'];
                  $document = $parsed_url['path'];
                  if($document[strlen($document)-1]=='/') $document = "$document/index.html";
                  $base_url = dirname($document);

                  $fp=fsockopen($myServer,80,&$errno,&$errstr,30);

                  // if you've name based virtual hosting
                  $request = "GET $document HTTP/1.1\r\n";
                  $request .= "Host: $myServer\r\n\r\n";
                  / if you've normal old type servers,
                  comment out the previous two lines and
                  use the next line instead
                  /
                  //$request = "GET $document HTTP/1.0\r\n\r\n";

                  if(!$fp) {
                  echo "$errstr ($errno)<br>\n";
                  } else {
                  fputs($fp,$request);
                  $content=0;
                  $in_title=0;
                  ?>
                  <HTML>
                  <HEAD>
                  <BASE HREF="<? echo "http://$myServer$base_url/"; ?>">
                  <STYLE TYPE="TEXT/CSS">
                  <!--
                  body,p {
                  background: #FFFFFF;
                  font-family: Verdana, Arial, Helvetica, sans-serif;
                  font-size: 10pt;
                  margin-left: 5px;
                  margin-top: 5px;
                  margin-right: 5px;
                  margin-bottom: 5px;
                  color: #000000;
                  text-align: justify;
                  }

                  TH.headerrow {
                  background-color: #CDC8B1;
                  font-family: verdana,courier;
                  font-size: 10pt;
                  color: black;
                  }
                  TD.datarow {
                  font-family: verdana,courier;
                  font-size: 10pt;
                  color: black;
                  }
                  //-->
                  </STYLE>
                  <?
                  while(!feof($fp)) {
                  $line=fgets($fp,4096);

                  // this is the stupid part - get the title
                  // python makes this so easy :-)
                  if(eregi("<title>",$line)){ $in_title=1; }
                  if ($in_title==1) $title.=$line;
                  if(eregi("</title>",$line)){
                  $in_title=0;
                  if(!eregi("<title>",$line))
                  $title.=$line;
                  }
                  if(ereg($START_CONT,$line)) {
                  $title = eregi_replace("</title>","",eregi_replace("<title>","",$title));
                  echo "<TITLE>$title</TITLE>\n</HEAD>\n<BODY>\n";
                  $content=1;
                  }
                  if(ereg($END_CONT,$line)) $content=0;
                  if($content==1)echo $line;
                  }
                  fclose($fp);
                  ?>
                  </BODY>
                  </HTML>
                  <?
                  }
                  ?>

                    Why don't you just do this:

                    ON THE GRAPHICLY ENHANCED PAGE - put this link

                    <a href="pf-pagename.php">Printer Friendly Version</a>

                    NOTE: the pf before the page name is just a way of knowing that it's the printer friendly version.

                    Then in on the printer friendly version, which CAN use PHP, just put this at the top of the page.

                    <?php
                    /* >>>>>>>>>> pf_pagename.php<<<<<<<<< */
                    ?>
                    <html>
                    <body>
                    <input type=button  
                    value="javascript:print.window();" name="Print Page"> </body> </html> <?php // now enter the rest of your page ?>

                    Doing it this way will allow you to create a dynamic page that can be printed no matter what extension is used.

                    This is the method that I use on ALL my printer friendly pages.

                      Originally posted by dniezby
                      Why don't you just do this:


                      ON THE GRAPHICLY ENHANCED PAGE - put this link

                      <a href="pf-pagename.php">Printer Friendly Version</a>

                      NOTE: the pf before the page name is just a way of knowing that it's the printer friendly version.


                      Then in on the printer friendly version, which CAN use PHP, just put this at the top of the page.

                      <?php
                      /* >>>>>>>>>> pf_pagename.php<<<<<<<<< */
                      ?>
                      <html>
                      <body>
                      <input type=button  
                      value="javascript:print.window();" name="Print Page"> </body> </html> <?php // now enter the rest of your page ?>

                      Doing it this way will allow you to create a dynamic page that can be printed no matter what extension is used.

                      This is the method that I use on ALL my printer friendly pages. [/B]

                      Thanks D, I will add this code to the print friendly page.

                      I had been using seperate printer-friendly pages and accessing them via the <link media="print"> tag.

                      I thought that I could of done the same thing with the php page, but I guess not.

                      CJ

                        there is a way to do it the way you'd like but that requires a lot more programing and takes a lot more time.

                        This way it's just quicker and a HELL of a lot easier.

                        Just copy and paste the printer friendly page and remove the graphics and stuff you don't want to print.

                          a month later

                          Can you perhaps tell me where you found printit.php? I have been looking for such a script. I would be greatly appreciated, I have looked all over for it.

                            Originally posted by degrand13
                            Can you perhaps tell me where you found printit.php? I have been looking for such a script. I would be greatly appreciated, I have looked all over for it.

                            Here is the link to printit:

                            http://www.phponline.biz/

                              Hi I noticed in the example you made use of some css styles to format your initial php page.

                              CSS allow us to specify which is the media we are using, it will apply the appropriate css style file accordingly to the media.

                              With a little work you may be able to print the page without any printer-friendly page.
                              Just add this code in the <head>:

                              <link rel="stylesheet" type="text/css" media="screen" href="screen_style.css">

                              <link rel="stylesheet" type="text/css" media="print" href="print_style.css">

                              The first tag embeds the css file for screen display, the second will be used if the page is printed, (and only for that).

                              With the power of css you will be able to display or hide elements from the page as you wish.

                              So with this solutions you get this advantages:

                              • only one page to display;
                              • the printing procedure can be done by the browser's print button or by any other mean (like javascript) directly
                              • css links dynamically generated ("Printing options? ...do you wish images printed or not? ...any graphic options? 🙂 ); you can have css.php files containing php & css code

                              And this drawbacks:

                              • high css page formatting using div tags and class style parameters, this can be hard work, but generally speeds the formatting and mantaining of the page
                              • css compatibility issues: but with more of 90% of windows-internet explorer 6 based users...

                              bye

                                Write a Reply...