【问题标题】:add border to pages printed using wkhtmltopdf为使用 wkhtmltopdf 打印的页面添加边框
【发布时间】:2014-10-19 06:59:03
【问题描述】:

类似于这个问题:Add borders to each printed page with CSS? 如何在使用 wkhtmltopdf 呈现的多页 pdf 的每一页上打印方形边框?

我创建一个 html 页面作为变量,并使用 snappy:https://github.com/KnpLabs/snappy 将其呈现为 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);

我尝试了一些方法,例如:

   ....
 <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>
 ...

但盒子会在页面上打断。 那么有什么想法可以在每页上以 10 毫米的边距打印黑色细边框吗? wkhtmltopdf 程序似乎没有正确处理通常的打印 css....

【问题讨论】:

    标签: html css printing wkhtmltopdf


    【解决方案1】:

    我快到了。

    只需要添加/更改

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

    &lt;style&gt; 标签中的我的 css 样式

    【讨论】:

    • 如果它只有 1 页,那就可以了。但多页不加边框。
    猜你喜欢
    • 1970-01-01
    • 2013-02-28
    • 2017-03-19
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    • 2013-08-23
    • 2011-09-14
    • 1970-01-01
    相关资源
    最近更新 更多