Php 如何创建A4页面大小的打印视图并固定每页的边框

Php 如何创建A4页面大小的打印视图并固定每页的边框,php,html,css,printing,laravel,Php,Html,Css,Printing,Laravel,我有一个关于php的html gen的大页面 并且希望使用html和css创建打印视图 我使用print.css样式创建此页面 然后有一些问题: 如何创建A4大小的页面 如何为所有页面和每页创建边框 如何在任何浏览器中创建固定大小视图 有php类来生成此吗? 谢谢你的回答:)这可能会对你有所帮助 <div id="printpage"> //blah blah </div> <a href="#" onclick="printdiv()">Pri


我有一个关于php的html gen的大页面
并且希望使用html和css创建打印视图
我使用print.css样式创建此页面
然后有一些问题:

  • 如何创建A4大小的页面
  • 如何为所有页面和每页创建边框
  • 如何在任何浏览器中创建固定大小视图
  • php类来生成此吗?

  • 谢谢你的回答:)
    这可能会对你有所帮助

    <div id="printpage">  
     //blah blah
    </div>  
    
    <a href="#" onclick="printdiv()">Print</a>
    
    function printdiv()
    {
        //your print div data
        //alert(document.getElementById("printpage").innerHTML);
        var newstr=document.getElementById("printpage").innerHTML;
    
        var header='<header><div align="center"><h3 style="color:#EB5005"> Your HEader </h3></div><br></header><hr><br>'
    
        var footer ="Your Footer";
    
        //You can set height width over here
        var popupWin = window.open('', '_blank', 'width=1100,height=600');
        popupWin.document.open();
        popupWin.document.write('<html> <body onload="window.print()">'+ newstr + '</html>' + footer);
        popupWin.document.close(); 
        return false;
    }
    
    
    //废话
    函数printdiv()
    {
    //打印div数据
    //警报(document.getElementById(“printpage”).innerHTML);
    var newstr=document.getElementById(“printpage”).innerHTML;
    var header='您的头


    ' var footer=“您的页脚”; //你可以在这里设置高度和宽度 var popupWin=window.open(“”,"u blank’,“宽度=1100,高度=600”); popupWin.document.open(); popupWin.document.write(“”+newstr+“”+footer); popupWin.document.close(); 返回false; }
    基础:

    在您的
    CSS
    打印样式中添加用于打印的媒体查询,并使用
    @page
    规则

    @media print{
      @page {
        size: auto;   /* auto is the initial value */
        size: A4 portrait;
        margin: 0;  /* this affects the margin in the printer settings */
        border: 1px solid red;  /* set a border for all printed pages */
      }
    }
    
    有php类来生成这个吗

    我不认为你真的需要额外的图书馆来做到这一点。但是,您可能需要一些浏览器兼容性。。。不是吗

    编辑

    要支持IE10+,您可能还需要添加此规则:

    /* IE10+ CSS print styles */
    @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
      /* IE10+ CSS print styles go here */
      @page {
        size: auto;   /* auto is the initial value */
        size: A4 portrait;
        margin: 0;  /* this affects the margin in the printer settings */
        border: 1px solid red;  /* set a border for all printed pages */
      }
    }
    

    您应该能够仅使用CSS来管理自己以打印网站内容。

    u可以使用Javascript。“window.print()”打印您当前的窗口。这是将页面大小设置为A4的好方法,但如何将每页的页面和边框装箱?这可能会帮助您: