在PHP中使用DomPDF我想得到相同的输出,当我们尝试在Chrome中保存为PDF

jfgube3f  于 2023-06-20  发布在  PHP
关注(0)|答案(1)|浏览(89)

我使用的是DomPDF,它工作正常,但**我面临的问题与PDF转换有关,当我尝试保存我的输出时,它需要两页,但是当我尝试在Chrome上保存HTML页面时,只需按Ctl+P并保存为PDF,它只显示一页输出。**我的代码如下:

<?php

require_once 'vendor/autoload.php';
use Dompdf\Dompdf;
use Dompdf\Options;

$options = new Options();
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);

ob_start();
include dirname(__FILE__).'\company_invoice.php';

$html = ob_get_clean();

// Load the HTML content of the invoice into the Dompdf object
$dompdf->loadHtml($html);

// Set the paper size and orientation of the PDF
// $dompdf->setPaper('A4', 'landscape');
 $dompdf->setPaper('A4', 'portrait');

// Render the PDF document
$dompdf->render();

// Output the generated PDF to the browser
$dompdf->stream('styled_page1.pdf');

?>

我同时使用了$dompdf->setPaper('A4', 'portrait')$dompdf->setPaper('A4', 'landscape'),也尝试了不使用setPaper。

uxhixvfz

uxhixvfz1#

下面是html代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<title>LabCloud Invoice</title>
<meta name="viewport" content="width=device-width, initial-scale=0.6">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
    body {
        /* margin-top: 20px; */
        color: #484b51;
        /* background-color: lightgray !important; */
    }

    .text-secondary-d1 {
        color: black !important;
    }

    .page-content {
        background-color: white !important;
        /* width: 900px; */
        padding: 0;

    }

    .content {
        /* width: 840px; */
        margin-left: 20px;
        margin-right: 20px;
        padding: 0;

    }

    @media print {
        .page-content {
            width: 100%;
            margin-left: 30px;
            padding: 0;
        }

        .content {
            width: 940px;
            margin-left: 20px;
            margin-right: 20px;
            padding: 0;
        }

        body {
            background-color: white !important;
        }
    }

    .page-header {
        margin: 0 0 1rem;
        padding-bottom: 0.5rem;
        padding-top: 0.5rem;
        border-bottom: 1px dotted #e2e2e2;
        display: -ms-flexbox;
        display: flex;
        -ms-flex-pack: justify;
        justify-content: space-between;
        -ms-flex-align: center;
        align-items: center;
    }

    .page-title {
        padding: 0;
        margin: 0;
        font-size: 1.75rem;
        font-weight: 300;
    }

    .ml-n1,
    .mx-n1 {
        margin-left: -.25rem !important;
    }

    .mr-n1,
    .mx-n1 {
        margin-right: -.25rem !important;
    }

    .mb-4,
    .my-4 {
        margin-bottom: 1.5rem !important;
    }

    hr {
        margin-top: 1rem;
        margin-bottom: 1rem;
        border: 0;
        border-top: 1px solid rgba(0, 0, 0, .1);
    }

    .text-grey-m2 {
        color: #888a8d !important;
    }

    .text-success-m2 {
        color: #86bd68 !important;
    }

    .font-bolder,
    .text-600 {
        font-weight: 600 !important;
    }

    .text-110 {
        font-size: 110% !important;
    }

    .text-blue {
        color: #C4261D !important;
    }

    .pb-25,
    .py-25a {
        padding-bottom: .75rem !important;
    }

    .pt-25,
    .py-25 {
        padding-top: .75rem !important;
    }

    .bgc-default-tp1 {
        background-color: #007CC3 !important;
        border-radius: 12px 12px 0px 0px;
    }

    .bgc-default-l4,
    .bgc-h-default-l4:hover {
        background-color: #f3f8fa !important;
    }

    .page-header .page-tools {
        -ms-flex-item-align: end;
        align-self: flex-end;
    }

    .btn-light {
        color: #757984;
        background-color: #f5f6f9;
        border-color: #dddfe4;
    }

    .w-2 {
        width: 1rem;
    }

    .text-120 {
        font-size: 120% !important;
    }

    .text-primary-m1 {
        color: #4087d4 !important;
    }

    .text-danger-m1 {
        color: #dd4949 !important;
    }

    .text-blue-m2 {
        color: #68a3d5 !important;
    }

    .text-150 {
        font-size: 150% !important;
    }

    .text-60 {
        font-size: 60% !important;
    }

    .text-grey-m1 {
        color: #7b7d81 !important;
    }

    .align-bottom {
        vertical-align: bottom !important;
    }

    .text-blue-m2 {
        color: #007CC3 !important;
    }

    .btn-info {
        background-color: #007CC3 !important;
    }

    .textline {
        width: 100px;
        margin-left: 0;
    }

    .flex-container {
        display: flex;
        justify-content: space-between;
    }

    .flex-item {
        flex: 1;
    }

    .text-left a {
        color: black;
        text-decoration: none;
    }

    .bgc-default-tp1 {
        background-color: #007CC3 !important;
        height: 40px;
    }

    .bgc-default-tp1 tr th
    {
       
    }

    .heading {
        font-size: 25px;
    }

    @media print {
        .action-buttons {
            display: none;
        }
    }

    @media print {
        .btn-info {
            display: none;
        }
    }
</style>

</head>
<body>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="page-content container-fluid">
    <div class="page-header text-blue-d2">
        <table class="col-12">
            <tbody>
                <tr>
                    <td class="" style="width: 70%;">
                        <h1 class="page-title text-secondary-d1">
                            Invoice
                            <small class="page-info">
                                <i class="fa fa-angle-double-right text-80"></i>
                                No: 1
                            </small>
                        </h1>
                    </td>

                    <td class="">
                        <div class="action-buttons">
                            <a class="btn bg-white btn-light mx-1px text-95" href="#" onclick="window.print()" data-title="Print">
                                <i class="mr-1 fa fa-print text-primary-m1 text-120 w-2"></i>
                                Print
                            </a>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>

    </div><!-- page-header text-blue-d2 -->
    <div class="container-fluid px-0">
        <div class="row mt-2 content">
            <div class="col-12 col-lg-12">
                <div class="row">
                    <div class="col-12 flex-container">
                        <table class="col-12">
                            <tbody class="text-600">
                                <tr>
                                    <td class="py-25 text-left text-150" rowspan="4" style="width: 70%; vertical-align: initial;">
                                            <span class="text-default-d3">

                                                <img class="img-fluid" src="https://lims.labcloud.pk/images/LabCloud.png" alt="LabCloud Logo" width="400">
                                            </span>
                                    </td>
                                    <td class="py-25">LabCloud</td>
                                </tr>

                                <tr>
                                    <td>
                                    <p class="text-left"><a href="https://wa.me/123" target="_blank">Whatsapp 0********</a></p>
                                    </td>
                                </tr>

                                <tr>
                                    <td>
                                         <p class="text-left"><a href="mailto:test@test.com" target="_blank">test@test.com</a></p>
                                    </td>
                                </tr>

                                <tr>
                                    <td>
                                         <p class="text-left"><a href="http://labcloud.pk" target="_blank">www.labcloud.pk</a></p>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>

                    <hr class="row brc-default-l1 mx-n1 mb-2" />
                    <div class="row">
                        <table class="col-12">
                            <tbody>
                                <tr>
                                    <td>
                                        <span class="text-sm text-grey-m2 align-middle">Client Information:</span>
                                    </td>

                                    <td class="py-25 text-grey-m2">
                                        Invoice
                                    </td>
                                </tr>

                                <tr>
                                    <td class="heading text-600" style="width: 70%;">
                                        <?=$client_name['name_on_invoice'];?>
                                    </td>

                                    <td>
                                        <div class="my-2 text-grey-m2">
                                            <i class="fa fa-circle text-blue-m2 text-xs mr-1"></i>
                                            <span class="text-600 text-90">Invoice No:1
                                        </div>   
                                    </td>
                                </tr>

                                <tr>
                                    <td></td>
                                    <td>
                                        <div class="my-2 text-grey-m2">
                                            <i class="fa fa-circle text-blue-m2 text-xs mr-1"></i>
                                            <span class="text-600 text-90">Invoice Date:</span> 16-06-2023
                                        </div>    
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td></td>
                                    <td>
                                        <div class="my-2 text-grey-m2">
                                            <i class="fa fa-circle text-blue-m2 text-xs mr-1"></i>
                                            <span class="text-600 text-90">Due Date:</span> 26-06-2023
                                        </div>   
                                    </td>
                                </tr>

                                <tr>
                                    <td></td>
                                    <td>
                                            <div class="my-2">
                                                <i class="fa fa-circle text-blue-m2 text-xs mr-1"></i>
                                                <span class="text-600 text-90 text-grey-m2">Status:</span>
                                                <span class="badge badge-warning badge-pill px-25">Unpaid</span>
                                            </div>
                                       
                                    </td>
                                </tr>
                             </tbody>
                        </table>
                    </div>
                    
                    <div class="mt-2">
                        <div class="row">
                            <table class="col-12">
                                <thead class="text-600 text-white bgc-default-tp1 ">
                                    <tr>
                                        <th class="py-25" style="border-radius: 12px 0px 0px 0px; height: 8px; padding-left: 20px;">#</th>
                                        <th class="py-25">Description</th>
                                        <th class="py-25">Qty</th>
                                        <th class="py-25">Unit Price</th>
                                        <th class="py-25">Disc.%</th>
                                        <th class="py-25" style="border-radius: 0px 12px 0px 0px;">Amount</th>
                                    </tr>
                                </thead>
                                <tbody style="height: 40px;">
                                      
                                    <tr>
                                        <td style="padding-left: 20px;">1</td>
                                        <td>Server Integration Charges</td>
                                        <td>1</td>
                                        <td>20,000 </td>
                                        <td>30%</td>
                                        <td>14,000</td>
                                    </tr>
                                    <tr>
                                        <td style="padding-left: 20px;">1</td>
                                        <td>Deployment</td>
                                        <td>1</td>
                                        <td>5,000 </td>
                                        <td>20%</td>
                                        <td>4,000</td>
                                    </tr>

                                </tbody>
                                <tfoot class="text-600 text-white bgc-default-tp1 py-25">
                                    <tr>
                                        <td style="border-radius: 0px 0px 0px 12px;" colspan="4"></td>
                                        <td>Net Amount</td>
                                        <td style="border-radius: 0px 0px 12px 0px;">18,000</td>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>

                    <div class="row mt-2">
                        <table class="col-12">
                            <tbody>
                                <tr>
                                    <td class="text-grey-d2 text-95 mt-2 mt-lg-0"><p>Please use the following communication for your payment : 1</p></td>
                                    <td>SubTotal:</td>
                                    <td><span class="text-120 text-secondary-d1">25,000</span></td>
                                </tr>

                                <tr>
                                    <td><p><b>Note:</b> Please clear your due amount within the due date to <br/> avoid any disturbance in services.</p></td>
                                    <td>Discount:</td>
                                    <td><span class="text-110 text-secondary-d1">7,000</span></td>
                                </tr>

                                <tr>
                                    <td colspan="1"></td>
                                    <td>Total Amount:</td>
                                    <td><span class="text-150 text-success-d3 opacity-2">18,000</span></td>
                                </tr>

                                <tr>
                                    <td colspan="3"> <hr /></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="row">
                        <table>
                            <tbody>
                                <tr>
                                    <td><p>You can make a payment using any of the following options.</p></td>
                                </tr>
                                <tr>
                                    <td><h6><b>Easypaisa and JazzCash</b></h6></td>
                                </tr>
                                <tr>
                                    <td><p>Account No: 03********</p></td>
                                </tr>
                                <tr>
                                    <td><h6><b>Online Transfer and Cash Deposit</b></h6></td>
                                </tr>
                                <tr>
                                    <td><p>Title Of A/c: Jhon Doe <br /> A/c #: 9************* <br /> Bank: Test Bank Limited</p></td>
                                </tr>
                                <tr>
                                    <td><h6><b>Cheque</b></h6></td>
                                </tr>
                                <tr>
                                    <td> <p>Title Of A/c: Jhon Doe</p></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                   
                    <hr/>
                    <div class="row mt-3">
                        <div>
                            <span class="text-secondary-d1 text-105">Thank you for your business</span>
                            <a href="#" class="btn btn-info btn-bold px-4 float-right mt-3 mt-lg-0 d-none">Pay Now</a>
                        </div>
                    </div>
            </div><!-- col-12 col-lg-12 -->
        </div><!-- row mt-4 content -->
    </div><!-- container px-0 -->
</div><!-- page-content container -->

<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript">

</script>
</body>
</html>

相关问题