如何从window.print中删除日期?

问题描述 投票:1回答:1

我创建了form看起来像PDF(Angular项目)。

我使用GOOGLE CHROME。

当我运行代码window.print时,浏览器会在视图上生成:

  1. 日期
  2. 文件名
  3. 页脚(带URL)

要更改我的标题,我使用 - > document.title = '\u00A0';要更改我的页脚,我使用 - >

let footer="NR_"+this.contractForm.contract_number";

window.history.pushState("object or st
ring", "Title", footer.replace("http://", ""));

如何更改/删除日期?

我知道我可以在选项中禁用页脚和标题,但我只想(!)删除日期。页脚对我来说非常必要。

我试过用一些技巧:

@page 
    {
        size: auto;   
        margin: 0mm; 
    }

但它对我不起作用。

javascript angular typescript
1个回答
0
投票

目前这是不可能的。你只能隐藏它们。最好的方法是创建自己的自定义页面,您可以在其中设置页面标题和页脚:

伪代码:

var pContents="
  <html>
    <title>Your custom title</title>
    <head></head>
    <body>
    <h1>
      Example Document
    </h1>
     <div>
      <p>
    This is an example document that shows how to have a footer that repeats at the bottom of every page, but also isn't covered up by paragraph text.
      </p>
     </div>
     <div>
      <h3>
         Example Section I
      </h3>
      <p>
         custom content
      </p>
     </div>
     <div class="content-block">
       <h3>Example Section</h3>
       <p>
         custom content
       </p>
     </div>
   <footer>
    This is the text that goes at the bottom of every page.
   </footer>
   <body>
</html>";

printMe(pContents);

function printMe(pageContents) {
 var printContents = pageContents;

 document.body.innerHTML = printContents;

 window.print();
}
© www.soinside.com 2019 - 2024. All rights reserved.