【问题标题】:remove url and print text from the printed page从打印的页面中删除 url 和打印文本
【发布时间】:2012-10-19 16:00:09
【问题描述】:

我开发了一个 Web 应用程序,在我的网页中有一些数据显示 常见的页眉、页脚、菜单和其他图像。所以我添加了一个小按钮作为打印 预览,以便用户只能看到数据。用户单击打印预览按钮后,仅显示数据 作为一个弹出窗口,在该弹出窗口中我添加了一个按钮调用 print 以便用户可以单击它并从该页面中打印出来。

这个打印按钮在 onClick 事件中直接调用 window.print() 并且它工作正常我可以得到打印输出。

但我的问题是在我的打印页面上,我可以在上面找到按钮标题的“打印”文本 我可以找到http://localhost/..............的网址

那么有没有一种方法可以从我的打印页面中删除那些打印文本和 url。

非常感谢

这就是打印预览按钮的作用。

function printPreView(reportCategory,reportType,transactionType,searchOption,customerRokaID,utilityCompany,fromDate,toDate,telcoName,bank){

var request = "selectedMenu="+reportCategory+"&loginStatus=success&criteria="+searchOption+"&customer="+customerRokaID+"&from="+fromDate+"&to="+toDate+"&nspTypes="+utilityCompany+"&trxTypes="+transactionType+"&options="+reportType+"&telcoTypes="+telcoName+"&bankTypes="+bank+"&printable=yes";


window.open ("report/showReport.action?"+request,null,"location=no,menubar=0,resizable=1,scrollbars=1,width=600,height=700");
}

这是我放置打印按钮的方式

 <form>

   <input type="button" value="Print" onClick="window.print() ">

 </form>

【问题讨论】:

  • 我认为“页面 URL”是根据浏览器中设置的用户首选项打印的(以便人们可以轻松地再次找到该页面),因此不太可能受到您的任何影响使用 JavaScript 或 CSS 实现。

标签: javascript html css jsp printing


【解决方案1】:

这对我有用,边距约为 1cm

@page 
{
    size:  auto;   /* auto is the initial value */
    margin: 0mm;  /* this affects the margin in the printer settings */
}
html
{
    background-color: #FFFFFF; 
    margin: 0mm;  /* this affects the margin on the html before sending to printer */
}
body
{
    padding:30px; /* margin you want for the content */
}

【讨论】:

    【解决方案2】:

    如果您使用的是引导程序,请找到以下代码:

     @media print {
      ...
      a[href]:after {
        content: " (" attr(href) ")";
      }
      ...
    }
    

    用 content:none 覆盖样式可以很好地处理这种情况。

    参考:this url

    【讨论】:

      【解决方案3】:

      带有 URL 的标题(有时是页面标题、页码等)由 Web 浏览器自动添加。基本上,设置只能由用户更改。这个话题详细讨论in that question

      对于按钮本身,您可以使用 that question 中讨论的特定打印 CSS 隐藏它。正如 MMacdonald 所说,您也可以将此技术用于其他元素,这样您就无需重新渲染页面。但是那样你会失去预览功能(用户仍然可以使用浏览器的打印预览功能)。

      【讨论】:

      • 这是正确答案。您可以从打印对话框更改设置。在页眉和页脚设置下,您可以更改打印设置。
      【解决方案4】:

      考虑使用media-dependent style sheets,而不是制作定制的“打印页面”解决方案。

      【讨论】:

        猜你喜欢
        • 2010-10-09
        • 2017-02-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-03
        • 1970-01-01
        • 2019-03-07
        相关资源
        最近更新 更多