add border to pages printed using wkhtmltopdf

左心房为你撑大大i 提交于 2019-12-13 06:49:45

问题


similar to this question: Add borders to each printed page with CSS? how can i print a square border on each page of a multi-page pdf that is rendered using wkhtmltopdf?

i create a html page as a variable, and use snappy: https://github.com/KnpLabs/snappy to render it to a pdf.

$html = $this->load->view('print/report_baseline_print',$data,TRUE);

    $snappy = new \Knp\Snappy\Pdf('path to wkhtmltopdf -O landscape');

    $tmp = random_temp_file('.pdf');
    $snappy->generateFromHtml($html,$tmp);
    $filename = 'Baseline-report.pdf';
    $this->output
            ->set_header("Cache-Control: no-cache, must-revalidate")
            ->set_header("Content-Disposition: filename=$filename;")
            ->set_content_type('application/pdf')
            ->set_output(read_file($tmp));
    delete_file($tmp);

I have tried a few things, like:

   ....
 <style>
    section:not(:last-child){
            page-break-after: always;
        }
    .box{
        border:1px solid black;
        position:fixed;
        top:10mm;
        right:10mm;
        bottom:10mm;
        left:10mm;
    }
</style>
</head>
<body>
   <section id='page1'>
     <div class='box'></div>
   </section>
   <section id='page1'>
     <div class='box'></div>
 ...

but the box breaks over the page. so any ideas how to get a thin black border to print on each page at 10mm margin? the wkhtmltopdf program seems to be not handling the usual print css properly....


回答1:


i was nearly there.

just needed to add/change

.box{
   border:1pt solid black;
   position:absolute;
   width:28.2cm;
   height:19.3cm;
} 

section{
   position:relative;
}

to my css styling within the <style> tags



来源:https://stackoverflow.com/questions/25497556/add-border-to-pages-printed-using-wkhtmltopdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!