Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove url and print text from the printed page

I have developed a web application and in my web page there are some data displays with common headers, footers , menus and other images. so I have added a small button as print preview so that user only can see data. After user click on print preview button only data display as a popup and in that popup I added a button call print so that user can click on it and take a print out of that page.

this print button directly call to window.print() in onClick event and it working fine I can get the print outs.

but my problem is in my printed page on top of that I can find the "Print" text which is button caption and in above that I can find the url which is something http://localhost/..............

So is there a way that I can remove those print text and url from my printed page.

Many Thanks

this is what the print preview button do .

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");
}

Here is how I have put my Print button

 <form>

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

 </form>
like image 386
someone Avatar asked Oct 30 '12 10:10

someone


People also ask

How do I print just the text from a website?

Only Print Text You Highlight on a Page Highlight the text and/or images you want to print on a web page. Now in your browser go to File > Print or simply use the Ctrl + P keyboard combination. The Print screen comes up. Select the Printer you want to use.

How do I remove header and footer in browser print?

If you want to remove the date or the page name in the header or footer, change your browser's print settings. The setting menu may differ depending on your browser version. on the upper right side of the screen, select Print > More settings > Options and then deselect Headers and footers.

How do I hide an element when printing a web page?

The media query is used to hide an element when printing web pages. Use @media print query and set the visibility hidden to that element that needs to hide at printing. Example 1: In this example, hide the element h1 at printing time. To hide the element h1 use media query and set visibility:hidden.


2 Answers

The header with the URL (and sometimes the page title, page number etc.) is automatically added by the web browser. Basically the settings can only be changed by the user. This topic is discussed in details in that question

For the button itself, you could hide it using specific print CSS as discussed in that question. And as MMacdonald said, you can use this technique for other elements as well so that you don't need to re-render your page. But then you would lose the preview feature (the user could still use the browser's print preview feature).

like image 154
Pierre Henry Avatar answered Oct 10 '22 14:10

Pierre Henry


If you're using bootstrap, find following code:

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

Overriding the style with content:none handles the situation fine.

Reference: this url

like image 38
Dhara Joshi Avatar answered Oct 10 '22 13:10

Dhara Joshi