使用PDF

时间:2015-08-26 11:58:03

标签: pdf reporting-services report dompdf

如何使用PDF打印报告?现在,我使用dompdf打印报告,但我们的小组说,当查看报告时,应该有一个取消按钮。

但是,当单击生成报告的按钮时,应该出现的pdf表单有一个打印和取消按钮。除了dompdf之外,有没有使用PDF生成报告的方法?

dompdf-master 是我本地系统中文件夹的名称,下面是生成报告的示例代码:

<?php
include('../connect-db-i.php');
require_once("../dompdf-master/dompdf_config.inc.php");

session_start();

ob_start();
?>

以下是报告的样式

<style>
<!-- CSS RESET -->
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

<!-- CSS RESET -->

html {
    margin: auto;
}

table {
    margin: auto;
    border: 1px solid lightgrey;
}

th {
    padding: 0px 10px;
}

th {
    border: 1px solid lightgrey;
    padding: 5px 24px;
}

td {
    border: 1px solid lightgrey;
    padding: 7px;
    margin: auto;
}

#mainCont {
    margin: auto 18px 5px 18px;
    padding: 10px;
    border-radius: 20px;
    border-top-right-radius: 20px;
    border-bottom-right-radius: 20px;
}

#img_main_logo {
    width: 200px;
    padding: auto;
    margin: auto;
}

#imgCont {
    margin: 6px;
    float: left;
}

#textCont {
    margin: 6px;
    float: right;
    width: 880px;
    height: 40px;
}

.title {
    font-size: 18px;
    margin-top: 12px;
    text-align: center;
    text-transform: uppercase;
}

#center {
    text-align: center;
}

#title {
    font-size: 20px;
}

#main_title {
    font-size: 22px;
}
</style>

以下是报告的开头

<?php
$month = date('F');

if($month == 'June' || $month == 'July' || $month == 'August' || $month == 'September' || $month == 'October' || $month == 'November' || $month == 'December')
{
    $year1 = date('Y');
    $year2 = date('Y') + 1;
    $preyear1 = date('Y') - 1;
    $preyear2 = date('Y');

    $schoolyear = $year1 . " - " . $year2;
    $preschoolyear = $preyear1 . " - " . $preyear2;
}

if($month == 'January' || $month == 'February' || $month == 'March' || $month == 'April' || $month == 'May')
{
    $year1 = date('Y') - 1;
    $year2 = date('Y');
    $preyear1 = date('Y');
    $preyear2 = date('Y') + 1;

    $schoolyear = $year1 . " - " . $year2;
    $preschoolyear = $preyear1 . " - " . $preyear2;
}
?>

这是报告的html

<html>
<body style="font-family: Helvetica;">
    <div id="mainCont">
        <div id="imgCont">
            <img id="img_main_logo" src="../image/logo/bnhslogo.png" />
        </div>
    </div>
    <div id="mainCont">
    <table border="0px">
        <tr>
            <td></td>
            <td></td>
            <td>
                <div id="textCont">
                    <p class="info" style="text-align: center;">
                    PTA ORGANIZATION
                    <br>BACNOTAN NATIONAL HIGH SCHOOL
                    <br>BACNOTAN, LA UNION
                    </p>
                </div>
            </td>
        </tr>
    </table>
    <table border="0px" style="margin-top: 60px;">
        <tr>
            <th></th>
            <th style='text-align: center;'>
                <b>DAILY REPORT OF GENERAL PTA</b>
            </th>
            <th></th>
        </tr>
        <tr>
            <th></th>
            <th style='text-align: center;'>
                <b>FOR SCHOOL YEAR <?php echo $schoolyear; ?> </b>
            </th>
            <th></th>
        </tr>
        <tr>
            <th></th>
            <th id = 'main_title'>PTA Fees and Authorized Fees<br></th>
            <th></th>
            <th></th>
        </tr>
    </table>
    </div>

    <table border="0px;" style="text-align: left;">
        <?php
            $user = $_SESSION['userlogin'];

            $student = mysqli_query($connection, "SELECT * FROM student WHERE schoolyear = '$schoolyear' AND status = 'Enrolled' OR status = 'Dropped'");
            $count = mysqli_num_rows($student);

            $result_collection = mysqli_query($connection, "SELECT * FROM collection WHERE schoolyear = '$schoolyear' AND type_trans = 'Daily'");
            $count_coll = mysqli_num_rows($result_collection);

            if($count_coll == 1)
            {

                while($row_col = mysqli_fetch_array($result_collection))
                {
                    $col_total_student = $row_col['total_student'];
                    $col_total_fee = $row_col['total_fee'];
                    $col_pta_fee = $row_col['pta_fee'];
                    $col_id_school = $row_col['id_school'];
                    $col_main_fee = $row_col['maintenance_fee'];
                    $col_electricity = $row_col['electricity'];

                    $result_sy = mysqli_query($connection, "SELECT * FROM ptafee WHERE schoolyear = '$schoolyear'");

                    while($row_pta = mysqli_fetch_array($result_sy))
                    {
                        $pta_fee = $row_pta['pta_fee'];
                        $main_fee = $row_pta['maintenance_fee'];
                        $id_school = $row_pta['id_school'];
                        $electricity = $row_pta['electricity'];
                        $total = $row_pta['total'];

                        $total_pta_fee = ($count * $pta_fee) - $col_pta_fee;
                        $total_main_fee = ($count * $main_fee) - $col_main_fee;
                        $total_id_school = ($count * $id_school) - $col_id_school;
                        $total_electricity = ($count * $electricity) - $col_electricity;
                        $total_fee = ($count * $total) - $col_total_fee;

                        echo "
                        <tr>
                            <td><br></td>
                            <td><br></td>
                            <td><br></td>
                        </tr>

                        <tr>
                            <td style='font-size: 18px;'><b>Miscellaneous Fees</b></td>
                        </tr>

                        <tr>
                            <td>PTA Fee: </td>
                            <td style='padding-right: 480px;'>P" . $pta_fee . "</td>
                        </tr>

                        <tr>
                            <td>Maintenance Fee: </td>
                            <td>P" . $main_fee . "</td>
                            <td></td>
                            <td></td>
                        </tr>

                        <tr>
                            <td>School ID: </td>
                            <td>P" . $id_school ." </td>
                            <td></td>
                            <td></td>
                        </tr>

                        <tr>
                            <td>Electricity: </td>
                            <td><u>P" . $electricity . "&nbsp;&nbsp;&nbsp;</u></td>
                            <td></td>
                            <td></td>
                        </tr>

                        <tr>
                            <td>Total Fees: </td>
                            <td>P" . $total . "</td>
                            <td></td>
                            <td></td>
                        </tr>

                        <tr>
                            <td><br></td>
                            <td><br></td>
                            <td><br></td>
                            <td><br></td>
                        </tr>

                        <tr>
                            <td style='font-size: 18px;'><b>School Year: </b></td>
                            <td>" . $schoolyear . "</td>
                            <td></td>
                            <td></td>
                        </tr>
                    </table>

                    <table border='0px' style='text-align: left;'>
                        <tr>
                            <td><b>Collected</b></td>
                            <td style='padding-right: 150px;'>&nbsp;</td>
                            <td><b>Collectibles</b></td>
                            <td style='padding-right: 150px;'>&nbsp;</td>
                        </tr>

                        <tr>
                            <td>PTA Fee: </td>
                            <td>P" . $col_pta_fee . "</td>
                            <td>PTA Fee: </td>
                            <td>P" . $total_pta_fee . "</td>
                        </tr>

                        <tr>
                            <td>Maintenance Fee: </td>
                            <td>P" . $col_main_fee . "</td>
                            <td>Maintenance Fee: </td>
                            <td>P" . $total_main_fee . "</td>
                        </tr>

                        <tr>
                            <td>School ID:</td>
                            <td>P" . $col_id_school . "</td>
                            <td>School ID:</td>
                            <td>P" . $total_id_school . "</td>
                        </tr>

                        <tr>
                            <td>Electricity:</td>
                            <td>P" . $col_electricity . "</td>
                            <td>Electricity:</td>
                            <td>P" . $total_electricity . "</td>
                        </tr>

                        <tr>
                            <td><b>Total: </b></td>
                            <td>P" . $col_total_fee . "</td>
                            <td><b>Total: </b></td>
                            <td>P" . $total_fee . "</td>
                        </tr>

                        <tr>
                            <td><br></td>
                            <td><br></td>
                            <td><br></td>
                            <td><br></td>
                        </tr>
                        ";
                    }
                }
            }

            if($count_coll == 0)
            {
                echo "
                <tr>
                    <th></th>
                    <th style='text-align: center;'>
                        <b>THERE ARE NO DAILY TRANSACTION FOR THIS SCHOOL YEAR</b>
                    </th>
                    <th></th>
                </tr>
                ";
            }

                echo "
            </table>

            <table border='0px;' style='text-align: left;'>
                <tr>
                    <td style='font-size: 18px;'><b>Previous Year: </b></td>
                    <td>" . $preschoolyear . "</td>
                    <td style='padding-right: 440px;'>&nbsp;</td>
                </tr>
            </table>
                ";
            ?>

            <table border="0px;" style="text-align: left;">
            <?php               
            $student = mysqli_query($connection, "SELECT * FROM student WHERE schoolyear = '$preschoolyear' AND status = 'Enrolled' OR status = 'Dropped'");
            $count = mysqli_num_rows($student);

            $result_collectionpre = mysqli_query($connection, "SELECT * FROM collection WHERE schoolyear = '$preschoolyear' AND type_trans = 'Daily'");
            $count_collpre = mysqli_num_rows($result_collectionpre);

            if($count_collpre == 1)
            {

                while($row_col = mysqli_fetch_array($result_collectionpre))
                {
                    $col_total_student = $row_col['total_student'];
                    $col_total_fee = $row_col['total_fee'];
                    $col_pta_fee = $row_col['pta_fee'];
                    $col_id_school = $row_col['id_school'];
                    $col_main_fee = $row_col['maintenance_fee'];
                    $col_electricity = $row_col['electricity'];

                    $result_sy = mysqli_query($connection, "SELECT * FROM ptafee WHERE schoolyear = '$preschoolyear'");

                    while($row_pta = mysqli_fetch_array($result_sy))
                    {
                        $pta_fee = $row_pta['pta_fee'];
                        $main_fee = $row_pta['maintenance_fee'];
                        $id_school = $row_pta['id_school'];
                        $electricity = $row_pta['electricity'];
                        $total = $row_pta['total'];

                        $total_pta_fee = ($count * $pta_fee) - $col_pta_fee;
                        $total_main_fee = ($count * $main_fee) - $col_main_fee;
                        $total_id_school = ($count * $id_school) - $col_id_school;
                        $total_electricity = ($count * $electricity) - $col_electricity;
                        $total_fee = ($count * $total) - $col_total_fee;

                        echo "

                        <tr>
                            <td><b>Collected</b></td>
                            <td style='padding-right: 150px;'>&nbsp;</td>
                            <td><b>Collectibles</b></td>
                            <td style='padding-right: 150px;'>&nbsp;</td>
                        </tr>

                        <tr>
                            <td>PTA Fee: </td>
                            <td>P" . $col_pta_fee . "</td>
                            <td>PTA Fee: </td>
                            <td>P" . $total_pta_fee . "</td>
                        </tr>

                        <tr>
                            <td>Maintenance Fee: </td>
                            <td>P" . $col_main_fee . "</td>
                            <td>Maintenance Fee: </td>
                            <td>P" . $total_main_fee . "</td>
                        </tr>

                        <tr>
                            <td>School ID:</td>
                            <td>P" . $col_id_school . "</td>
                            <td>School ID:</td>
                            <td>P" . $total_id_school . "</td>
                        </tr>

                        <tr>
                            <td>Electricity:</td>
                            <td>P" . $col_electricity . "</td>
                            <td>Electricity:</td>
                            <td>P" . $total_electricity . "</td>
                        </tr>

                        <tr>
                            <td><b>Total: </b></td>
                            <td>P" . $col_total_fee . "</td>
                            <td><b>Total: </b></td>
                            <td>P" . $total_fee . "</td>
                        </tr>
                    ";
                    }
                }
            }

            if($count_collpre == 0)
            {
                echo "
                <tr>
                    <th></th>
                    <th style='text-align: center;'>
                        <b>THERE ARE NO DAILY TRANSACTION FOR THIS SCHOOL YEAR</b>
                    </th>
                    <th></th>
                </tr>
                ";
            }
            ?>

            </table>

                <?php
                $date = DATE("F j, Y");
                $time = DATE("g:i A");

                echo "
                    <table border='0px' style='text-align: left;'>
                        <tr>
                            <th><br></th>
                            <th><br></th>
                            <th><br></th>
                            <th><br></th>
                        </tr>

                        <tr>
                            <th><br></th>
                            <th><br></th>
                            <th><br></th>
                            <th><br></th>
                        </tr>

                        <tr>
                            <th style='font-size: 18px;'><b>Date: </b></th>
                            <th>" . $date . "</th>
                            <th style='font-size: 18px;'><b>Reprinted By: </b></th>
                            <th>" . $user . "</th>
                        </tr>

                        <tr>
                            <th style='font-size: 18px;'><b>Time: </b></th>
                            <th>" . $time . "</th>
                        </tr>
                        ";

            /*if($count_collpre == 0)
            {
                echo "
                <tr>
                    THERE ARE NO DAILY TRANSACTION FOR THE PREVIOUS SCHOOL YEAR
                </tr>
                ";
            }*/
            ?>
    </table>
</body>
</html>

这是报告的最后一个php

<?php
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper('folio', 'portrait');
$dompdf->render();
//$dompdf->stream("report.pdf");
$dompdf->stream('report.pdf',array('Attachment'=>0));
?>

0 个答案:

没有答案