-3

这是我打印 qoutation 的代码。我已经为此使用了javascript。你能告诉我我应该怎么做才能只打印报价而不是整页吗?此代码打印完整的网页。我希望它以 pdf 格式打印

<?php 
session_start();


if(empty($_GET['id']))
    {
        header("location:products.php");
    }

    require_once("include/database.php");

    $_SESSION['p_id'] = $_GET['id'];
    $query = "SELECT * from products WHERE p_id='".$_GET['id']."'";

    $res = mysql_query($query,$connection) or die("wrong query " .mysql_error());
    $row = mysql_fetch_array($res);

    if(mysql_num_rows($res) != 1)
    {
        header("location:products.php");
    }

?>
<head>
<link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz|Open+Sans:400,600,700|Oswald|Electrolize' rel='stylesheet' type='text/css' />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />

    <title>Siddhivinayak Motors Pvt. Ltd. | Home</title>

    <meta name="description" content="" />
    <meta name="author" content="" />
    <link rel="icon" href="images/favicon.ico" />
    <link rel="stylesheet" href="css/style.css" media="screen" />
    <link rel="stylesheet" href="css/skeleton.css" media="screen" />
    <link rel="stylesheet" href="sliders/flexslider/flexslider.css" media="screen" />
    <link rel="stylesheet" href="fancybox/jquery.fancybox.css" media="screen" />



    <!-- HTML5 detect touch events -->
    <script type="text/javascript" src="js/modernizr.custom.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>


<body class="menu-1 h-style-1 text-1">
<div class="wrap">

    <!-- - - - - - - - - - - - - - Header - - - - - - - - - - - - - - - - -->   
    <?php 
    include("include/header.php");
    ?>

    <!-- - - - - - - - - - - - - - end Header - - - - - - - - - - - - - - - - -->   


<aside id="sidebar" class="one-third column">

        <div class="widget-container widget_compare">

    <div class="widget-head">
        <h3 class="widget-title">Price Quotation</h3>
    </div>

    <div class="entry-loan">

    <form action="php/service.php" method="POST" name="service" id="service" >
        <input type="hidden" name="id" value="<?php echo $_GET['id'] ?>"/>
    <table>

       <tr height="40px">
       <td><label for="Vehicle name">Vehicle</label></td>
       <td style="padding:0 0 0 12px; ">
       <label>  
        <?php  
        echo $row['p_name'];
        ?>
    </label>
    </td>
    </tr>

    <tr height="40px">
     <td><label for="Vehicle name">Model</label></td>
    <td style="padding:0 0 0 12px; "><label>
    <?php  
        echo $row['p_subname'];
    ?>
     </label>
    </td>
     </tr>

    <tr height="40px">
    <td><label for="Vehicle name">Ex-Showroom price</label></td>
    <td style="padding:0 0 0 12px; ">
    <label><?php echo $row['showroom_price'] ?></label>

    </td>
    </tr>
    <tr>
    <td colspan="2" style="padding:70px 0 0 120px; ">
    <i>As on. &nbsp;  &nbsp; &nbsp;<?php  
            echo date("d-m-Y");
                ?>
<br/>
    Tax and insurance extra.<br/>
   All prices are subject to change without prior notice.<br/>
    Please contact the dealership for exact prices and offers.<br/></i>
    </td>
   </tr>

    <tr>
    <td colspan="2" style="padding:0 0 0 12px; ">
    </td>
    </tr>

    <tr>
    <td></td>
    <td style="padding:0 0 0 20px; ">

     <script language="JavaScript"> 
    if (window.print) {
        document.write('<form><input type=button name=print value="Print" onClick="window.print()" class="button orange"></form>');
                            }
    </script>
    </td>
    </tr>

    </table>                    

    </form>

    </div>


        <!-- - - - - - - - - - - - - end Container - - - - - - - - - - - - - - - - -->          

    </div><!--/ .main-->


    <!-- - - - - - - - - - - - - - - Footer - - - - - - - - - - - - - - - - --> 
    <?php
          include("include/footer.php");
    ?>

    <!-- - - - - - - - - - - - - - - end Footer - - - - - - - - - - - - - - - - -->     

</div><!--/ .wrap-->
<?php
    include("include/login.php");
?>
<?php mysql_close($connection); ?>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.7.2.min.js"><\/script>')</script>
<!--[if lt IE 9]>
    <script src="js/selectivizr-and-extra-selectors.min.js"></script>
<![endif]-->
<script src="sliders/flexslider/jquery.flexslider-min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="js/jquery.gmap.min.js"></script>
<script src="js/jquery-impromptu.js"></script>
<script src="js/custom.js"></script>
</body>
</html>
4

1 回答 1

0

使用 CSS 媒体查询。

.extra {
    display: block;
}

@media print {
    .extra {
        display: none;
    }
}

默认情况下显示元素,但是当浏览器想要打印页面时,它会看到打印媒体查询并应用它,隐藏元素。

如果您想以 PDF 格式打印,那就完全不同了。在将任何输出发送到客户端之前,您需要在 PHP 中发送特殊的 PDF 标头:

header('Content-type:application/pdf'); 
于 2013-05-01T06:59:34.660 回答