Print Stylesheet - Converting Inputs to Text

Print Stylesheet - Converting inputs to text

Nope, I don't think this can be done without some scripting. But the scripting would be really easy to achieve with a Framework like Jquery:

  • For each input element, you would create a <span> next to it and give it a class that is hidden in the media="screen" stylesheet, and visible in media="print".

  • The input element itself would get a class that works the other way round, visible in screen and hidden in print.

  • Each input element would get a change event that updates the neighboring span.

I don't have the JQuery routine yet to pull this out of my sleeve, and not the time to put it together right now, but it is definitely solvable and still quite unobtrusive - no need to execute any scripting when the user starts printing.

I bet if you re-tag the question or ask a new one, one of our resident JQuery gurus will take a look at it :)

Couple Print Stylesheet Questions

Yes, there is. It's called @media and has been supported in major browsers for a while.

So, let's say that you had something like:

<img class="no-print" src="image" /><span class="print">Image Label</span>

Your style sheet could be something like:

<stye>
.print {display: none;} // only to be displayed when this is being printed so the default is to not display
@media print {
.print {display: inline}
.no-print {display: none}
}
</style>

converting input type text to plain text

This should do it I think.

function disable_all() {
var fs = $("#fileserver"), span = $( "<span>" + fs.val() + "</span>");
span.insertAfter(fs);
fs.remove(); // or fs.hide(); in case you want it later.
}

Conversion of a webpage to text

Use the BeautifulSoup library together with the requests library will get you at least to a good start. Once you study the first library some more, you might be able to customize your program to extract only the text you want. See below.

Also, please see here for a similar question: Text Extracting: Used All Methods, Yet Stuck.

import requests
from bs4 import BeautifulSoup

url = 'http://www.uniprot.org/'
content = requests.get(url)
soup = BeautifulSoup(content.text)
print(soup.text)

(Partial) output, hand-picked:

...
The mission of UniProt is to provide
the scientific community with a comprehensive, high-quality and
freely accessible resource of protein sequence and functional
information.
UniProtKBUniProt KnowledgebaseSwiss-Prot (564,277)Manually annotated and reviewed.Records with
...


Related Topics



Leave a reply



Submit