1

While exporting my aspx page to pdf, at the top right corner of the page, I am getting the url of the page and at the bottom right corner, it is showing datetime. How can I remove this from the pdf page?

And I have to reduce the left and right margin of the pdf page and also change the fonts size? Is it possible?

<div id="printIt">
            // data grid 
        </div>
        <asp:Button ID="btn_print" runat="server" ClientIDMode="Static" Text="Print" OnClientClick="printPage();" />

js code

 function printPage() {
        var headstr = "<html><head><title></title></head><body>";
        var footstr = "</body>";
        var newstr = document.getElementById("printIt").innerHTML;
        var oldstr = document.body.innerHTML;
        document.body.innerHTML = newstr;
        window.print();
        document.body.innerHTML = oldstr;
    }

How can I modify this print function to::

1. remove url and date time from top of the pdf
2. set left and right margins for the pdf page
3. set font size and font type for pdf page
nischalinn
  • 1,133
  • 2
  • 12
  • 38

2 Answers2

2

Try using CSS properties

Styling:

@media print {
  body {
    font-size: 14px;
    font-family: 'Times New Roman'
  }
 }

Positioning:

@page {
  margin: 0cm 2cm 0cm 2cm;
}
Lab Lab
  • 781
  • 10
  • 34
  • Where to keep this `CSS` properties? I mean how to link this `CSS` properties to the `pdf` page? I am doing this for first time, please help!!! – nischalinn Mar 19 '19 at 02:13
1

If it is for printing purpose, you can use paper.css

https://github.com/cognitom/paper-css

examples

https://github.com/cognitom/paper-css/blob/master/examples/a4-landscape.html

All available page sizes CSS available

  • A5, A5 landscape
  • A4, A4 landscape
  • A3, A3 landscape
  • letter, letter landscape
  • legal, legal landscape

Thank You.

user4221591
  • 2,084
  • 7
  • 34
  • 68