Jump to content
  • 0

How to hide the text "Print this Page" on the Print Page window in Print Button script?


Cherry

Question

Hi Everyone,

I added a print this page button. I customized the style. It is working, but the Print this Page text still visible under the Print Page Window.

How to get rid of the PDF Text?

Please see attached screenshots. 

Thanks a lot.

-Cherry

 

Below is the styling and script I used.

 

<style>

button {
  background-color: blue;
  border: none;
  color: white;
  padding: 8px 20px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius:4px;
}

</style>

<!-- -- PRINT BUTTON--->
<div style="margin-left: 330px; margin-top: 10px; margin-bottom: 10px;">
<button onclick="window.print()">PDF</button>
</div>

<!-- -- SCRIPT--->
<script type="text/javascript">
    function printpage() {
        //Get the print button and put it into a variable
        var printButton = document.getElementById("printpagebutton");
        //Set the print button visibility to 'hidden' 
        printButton.style.visibility = 'hidden';
        //Print the page content
        window.print()
        //Set the print button to 'visible' again 
        //[Delete this line if you want it to stay hidden after printing]
        //printButton.style.visibility = 'visible';
    }
</script>

 

printtopdfbutton.thumb.png.f338b946feae957c074b8c1169ec6473.pngthepdftextstillvisible.thumb.png.b4773313731373c20479d86129292261.png

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

First thing I noticed is that you are not using the print function in the script that you have. You are using the default window.print() function.

 

<div style="margin-left: 330px; margin-top: 10px; margin-bottom: 10px;">
<button onclick="window.print()">PDF</button>
</div>

<!-- -- SCRIPT--->
<script type="text/javascript">
    function printpage() {
        //Get the print button and put it into a variable
        var printButton = document.getElementById("printpagebutton");
        //Set the print button visibility to 'hidden' 
        printButton.style.visibility = 'hidden';
        //Print the page content
        window.print()
        //Set the print button to 'visible' again 
        //[Delete this line if you want it to stay hidden after printing]
        //printButton.style.visibility = 'visible';
    }
</script>


Try changing those lines to this:

 

<div style="margin-left: 330px; margin-top: 10px; margin-bottom: 10px;">
<button onclick="printpage()">PDF</button>
</div>

<!-- -- SCRIPT--->
<script type="text/javascript">
    function printpage() {
        //Get the print button and put it into a variable
        var printButton = document.getElementById("printpagebutton");
        //Set the print button visibility to 'hidden' 
        printButton.style.visibility = 'hidden';
        //Print the page content
        window.print();
        printButton.style.visibility = 'visible';
    }
</script>

See if that works.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...