打印dompdf时PDF容易破解

时间:2019-07-15 07:57:17

标签: php zend-framework2 dompdf

嗨,我正在使用dompdf从HTML生成pdf,但无法理解为什么在打印pdf时会损坏

这是我的功能

public function printRunsheetBymanifestAction()
{
    $manifestId = $this->params()->fromRoute('id', 0);
    $getDetails = $this->getDeliveryTable()->getRunSheetData(array('manifestId' => base64_decode($manifestId)));
    $getItemDetails = $this->getManifestTable()->getManifestItemsById($getDetails[0]['manifestId']);
    $options = new Options();
    $options->set('isRemoteEnabled', true);
    $options->set('defaultFont','Courier');
    $options->set('defaultPaperSize','A4');
    $domPdf = new \Dompdf\Dompdf($options);
    $domPdf->set_option('isHtml5ParserEnabled', true);
    $view = $this->getServiceLocator()->get('ViewRenderer');
    $viewModel = new ViewModel();
    $viewModel->setTemplate('delivery/index/print-runsheet-bymanifest.phtml');
    $viewModel->setVariable('results', $getDetails);
    $viewModel->setVariable('itemDetails', $getItemDetails);
    $content = $view->render($viewModel); //make html content for loadn in doampdf
    $domPdf->loadHtml($content);
    $domPdf->render();
    $fileName = $getDetails[0]['runsheetNumber'].'_'.date('d_m_Y');
    $domPdf->stream($fileName,array("Attachment"=>1));
    exit;
}

这是我的phtml模板,即使我尝试使用分页符CSS在所需的输出后分页也是如此

<?php $results = $this->results;
$items = $this->itemDetails;
?>
<style>
table.body {
                width: 100%;
               margin: 0 auto;
            }
td.text-right{text-align: right;}
td.text-center{text-align: center;}
.page_breack{
    clear: both;
    page-break-after: always;
}
</style>
<table class="body" align="center" style="border-top: 1px solid #333; border-left: 1px solid #333; border-right: 1px solid #333;">
<tr>
    <td>
        <div id="header">
        <table style="width: 100%; border-collapse: collapse;">
        <tr>
        <td style="width: 30%">
            <img style="width: 250px" src="<?=$this->basePath();?>/manifests/generate-barcode/<?php echo $results[0]['runsheetNumber']; ?>">
        </td>
        <td style="width: 70%">
        <table class="row" style="width: 100%">
            <tr>
            <td >Location: <?php echo $results[0]['branchName']; ?></td>
            </tr>
            <tr>
            <td >Website: www.xfas.in</td>
            </tr>
            <tr>
            <td >
            Daily Runsheet for : <?php echo $results[0]['allocated'.$results[0]['allocatedTo'].'Code'].' - '.$results[0]['allocated'.$results[0]['allocatedTo'].'Name']; ?>
            </td>
            </tr>
            <tr>
            <td class="text-right">
                <strong>Printed @ : <?php echo date('d.m.Y'); ?></strong>
            </td>
            </tr>
        </table>
        </td>
        </tr>
        </table>
        </div>
    </td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<table width="100%" style="border-collapse: collapse;">
<tr>
<th style="border-bottom: 2px dashed #333; border-top:2px dashed #333; text-align: center; height: 15px; ">SNo.</th>
<th style="border-bottom: 2px dashed #333; border-top:2px dashed #333; text-align: center; height: 15px; ">AwbNo.</th>
<th style="border-bottom: 2px dashed #333; border-top:2px dashed #333; text-align: center; height: 15px; ">Consignee Details</th>
<th style="border-bottom: 2px dashed #333; border-top:2px dashed #333; text-align: center; height: 15px; ">Pin Code</th>
<th style="border-bottom: 2px dashed #333; border-top:2px dashed #333; text-align: center; height: 15px; ">Signature</th>
</tr>


<?php if(count($items) > 0):
foreach ($items as $key => $val):
// $key = $key +1;
?>

<tr class="<?php 
    ++$key; 
    if($key%14 == 0 && $key !=0)
    echo "page_breack";
    //echo ++$key; ?>" ><td style="font-size: 12px; text-align:center; height: 65px; border-bottom: 1px solid #333; border-top:1px solid #333; border-collapse: collapse;"><?php echo $key; ?></td>
<td style="font-size: 12px; text-align:center; height: 65px; border-bottom: 1px solid #333; border-top:1px solid #333; border-collapse: collapse;"><?php echo $val['Awb']; ?></td>
<td style="font-size: 12px; text-align:center; height: 65px; border-bottom: 1px solid #333; border-top:1px solid #333; border-collapse: collapse;"><strong><?php echo $val['Consignee']; ?></strong><br>
<?php echo $val['Address'].', '.$val['Place'].', '.$val['ConsigneeArea']; ?>
</td>
<td style="font-size: 12px; text-align:center; height: 65px; border-bottom: 1px solid #333; border-top:1px solid #333; border-collapse: collapse;"><?php echo $val['PinCode']; ?></td>
<td style="font-size: 12px; text-align:center; height: 65px; border-bottom: 1px solid #333; border-top:1px solid #333; border-collapse: collapse;"></td>
</tr>
<?php endforeach; ?>
<?php 
    $ramainRow = count($items)%14;
if($ramainRow >0){ 
    // $cnt =  14 - count($items); 
for ($i =0; $i < $ramainRow; $i++){?>
    <tr>
    <td colspan="5" style="font-size: 12px; text-align:center; height: 65px; border-bottom: 1px solid #333; border-top:1px solid #333; border-collapse: collapse;"></td>
    </tr>
<?php } ?>
    <tr>
    <td colspan="5" style="font-size: 12px; text-align:center; height: 53px; border-bottom: 1px solid #333; border-top:1px solid #333; border-collapse: collapse;">
    <strong>Receiver Name:</strong> <?php echo $results[0]['allocated'.$results[0]['allocatedTo'].'Code'].' - '.$results[0]['allocated'.$results[0]['allocatedTo'].'Name']; ?><br>
    <strong>Signature:</strong>
    </td>
    </tr>
<?php }?>
<?php endif;?>
</table>
</td>
</tr>

上面是htm格式文件,用于更好地理解我正在查看pdf fil

enter image description here

enter image description here

0 个答案:

没有答案