Solved

print what you see in the screen with jscript vbscript or something else

Posted on 2004-04-30
16
3,358 Views
Last Modified: 2007-12-19

hi everybody !

i have a html page : for example this :

<html>
<script>(my vb or jscript)
</script>
<table>
<tr>
   <td>hello</td>
</tr>
</table>
<button onclick="printMyPage()">print the screen</button>
</html>

i want a solution  in vbscript or javascript or vbscript and javascript together or something else that do :

1) the user click on the button that call the function printMyPage()
2) get the actual window size ( S )
3) maximaze the actual window.
4) do ALT+ PRINT SCREEN
5) print the result of the 4)
6)return the size of the window to the initial size ( S ).

thanks.
 
0
Comment
Question by:prince_jean
  • 5
  • 3
  • 2
  • +3
16 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 10959827
The page is always printed independent of window maximization state.
The contentent does not change on window change, and only the content is printed.
If you do not want to print the content but the window hardcopy, then you will do not succeed in doing that with JavaScript.

0
 
LVL 2

Expert Comment

by:Hurb
ID: 10962587
Just use the javascript:
print()

Simple.. Eh...
The user will get the print box prompt that I'm sure everybody is familiar with. They can chose to print selection, all, page x to y. They can chose the amount of copies and so on...
0
 

Author Comment

by:prince_jean
ID: 10968637
i don't want to use the print() function because it doesn't print what i see in the window.
( when i use the print function what i print is not what i se, for that to be sure that what i print is what i see : i want to use the shot screen)
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 10970769
My thought was to use SendKeys to send Alt+PrintScreen to the window like so...

        var oShell= new ActiveXObject("WScript.Shell");
        oShell.SendKeys( "%{PRTSC}" );

However that fails.  The documentation states:

    >>Note You can't use SendKeys to send keystrokes to an application that is not
                 designed to run in Microsoft Windows.  Sendkeys also can't send the
                  PRINT SCREEN key {PRTSC} to any application.

The reason for this is most likely a security-related issue.

There are a number of ActiveX modules and standalone programs that will take a snapshot of window or the entire destktop.  For instance:
      http://www.softlookup.com/display.asp?ID=23387&RID=8740707&DID=4J58YURT
      http://www.thescarms.com/vbasic/capture.asp
      http://www.techsmith.com/products/snagit/tour/capture.asp

The rest of the problem is trivial.  If you decide to use a tool like this for step 4 and still need hlp with steps 1,2,3, 5, or 6, just say so.

=-=-=-=-=-=-=-=-=-=-
Note:  Usually questions like this are really about capturing a specific element of the screen.  If so, then perhaps a more complete description of the problem would help shake loose an alternative to the above "No, it can't be done" answer :).

-- Dan
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10972679
If you mean when they scroll, you only want to print the section you see, I wrote a script that doesn't do a screen capture, but is a pretty good workaround. Paste the following script somewhere in the page. At any time, press P to see the popup window with only that section.

-------------------------------------------------------------------------
<script>
function takeShot(){
  if(event.keyCode!=112){return;}
  var w=document.body.scrollLeft+document.body.offsetWidth;
  var h=document.body.scrollTop+document.body.offsetHeight;
  var t=-document.body.scrollTop;
  var l=-document.body.scrollLeft;

  var win=window.open("","","left=0,top=0,width="+w+",height=" +h+ ",status=no,scroll=no,menubar=yes, toolbar=no,location=no,directories=no,resizable=no");
  win.document.open();
  win.document.write("<div style='overflow:hidden;width:"+w+"px;height:" +h+ "px;position:absolute;top:"+t+";left:"+l+";'>"+document.body.innerHTML+"</div>");
  win.document.close();
  win.document.body.style.margin=0;
}
document.onkeypress=takeShot;
</script>
0
 

Author Comment

by:prince_jean
ID: 10978608
ok thank u for u comment.

DanRollins : ok i saw that u understand what i want - i've tryed
     oShell.SendKeys( "%{PRTSC}" ); too and it doesn't work... sh*t this is the only keys
that doesn't work (print screen);
all the link that you give me are very intersting but ther are not for me because there
are some programs that do "shot screen".
i don't want to tell to my users to use a program . i want to put a button "print"
in my html page , and i want that it will automatically  print the shot screen.
but i don't want that the users have to do it manually.
do you know something else as the senKeys(PRTSC)  ? ;
 I know that in visual basic we can shot the screen as an image and print the image.
but in vb script or javascript i don't know if we can do that ... do u know how to ?
can the active X do that?


lil_puffball : ur code is good but i want a solution to do screen shot in the code (not manually),
do u know how to ?

thanks


prince_jean.



0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 49

Expert Comment

by:DanRollins
ID: 10982597
There is an off chance that an ActiveX program could use Win32 API fn SendInput(), specifying VK_SNAPSHOT.  But though the program to do that would be relatively trivial, it is outside of the realm of Javascript :)

Remind me why a normal printing is no good?  What is missing from it that would be seen in a screenshot?

What a lot of sites do is create a printer-friendly version of the page and have the user print that.  For instance:

       http://www.experts-exchange.com/viewQuestionPrinterFriendly.jsp?qid=20973595

-- Dan
0
 

Author Comment

by:prince_jean
ID: 10985968
i have a very big table and a lot of div.
the position of the divs are not the same in the screen and in the paper.
one of the problem is a question that i have post in the html forum :



pb in the text of td in table when printing it ( or print preview) :

hi
 
here is a code of html :

<html>
<table style="font-family:arial;font-size:8pt;cellspacing:0;cellpadding:0;table-layout:fixed;border-collapse:collapse;">
<tr>
<td style="width:40px;height:25px;background-color:beige;border:1px solid black">this is a very long string</td>
<td style="border:1px solid black" >a</td>
</tr>
<tr>
<td style="border:1px solid black" >a</td>
<td style="border:1px solid black" >a</td>
</tr>
</table>
</html>


when you see the page in internet explorer you don't see all
the text in the first td ("this is a very long string"), because there is a specific
width and height in the td - and that is what i want .

My problem is when i want to print the page ( or print preview), we see all
the text and the height of the specific td is bigger - this is not good for me.
How can i correct the problem without changing the table-layout and border collapse properties ?

thanks.

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 10989214
As I'm certain the HTML geniuses will tell you it is *quite utterly* impossible to maintain fidelity between what is seen on the screen and what gets printed.  There are specific reasons why this happens, but they are too numerous to mention and you can't possibly overcome them all.  Period.  It is the single most commonly asked question in that TA the correct aswer is *always* "No, it can't be done."  

That is why so many websites do as I suggested: They provide a simplified "printer-friendly" verision of certain pages that the user will commonly need to print.  That is not a complete solution, but it fixes the problem for a majority of the users.

-- Dan
0
 
LVL 1

Expert Comment

by:mjhLakewood
ID: 11224189
Hope this helps.

<HTML>
<Body>
<Div align=center>
<h3>Resizable and printable text frame<br>
with a background image</h3>
<IFRAME
    SRC="/Text.html"
    WIDTH=""
    HEIGHT=""
    Scrolling = "auto"
    Frameborder = "yes">
</IFRAME>
</Div>
</Body>
</HTML>

Here's the Text.html file.

<HTML>
<HEAD>
<Style>

Body {
         Background-Color="#FFF8DC";
         Background-Image : url(graybars.gif);
        Font-Size : 14pt;
         Text-Align : Justify;
         Text-Indent : 12;
         Margin-Left : 10;
         Margin-Right : 10
}
 
.Blue14 {
      FONT-SIZE: 14pt; COLOR: "Blue"; FONT-FAMILY: "Times New Roman",
      Verdana, Arial, Helvetica, sans-serif;
}
   

 INPUT {
      Cursor: Pointer;
      background-color=lightblue;
      BORDER-RIGHT: Black 2px solid;
      BORDER-TOP: #999999 1px solid;
      FONT-SIZE: 14pt;
      BORDER-LEFT: #999999 1px solid;
      BORDER-BOTTOM: Black 2px solid;
      FONT-FAMILY: "Times New Roman", Verdana, Arial, Tahoma, Rockwell, system;
      COLOR: #000000;
}
</Style>

<Script Language=JavaScript>
      
      var Idx = 300;
            
      function setCookie(name, value) {
                    var curCookie = name + "=" + value;
                    document.cookie = curCookie;
      }


      
      function getCookie(name) {
                    var dc = document.cookie;
                    var prefix = name + "=";
                    var begin = dc.indexOf("; " + prefix);
                    if (begin == -1) {
                            begin = dc.indexOf(prefix);
                            if (begin != 0) return null;
                          } else
                                  begin += 2;
                                var end = document.cookie.indexOf(";", begin);
                                if (end == -1)
                                  end = dc.length;
                                return unescape(dc.substring(begin + prefix.length,                               end));
      }


      function incrIdx(){
            Idx=Idx-100+200;
            setCookie('Txt1',Idx);
      }

      function decrIdx(){
            Idx = Idx-100;
            setCookie('Txt1',Idx);
            if (Idx == 300){document.getElementById('minusTop').disabled = true;
                        document.getElementById('minusBottom').disabled = true;}
      }

      function longer(){
            if (Idx < 1000){window.resizeBy(0,100)
                        incrIdx();
                        document.getElementById('minusTop').disabled = false;
                        document.getElementById('minusBottom').disabled = false;}
      }
                        
      function shorter(){
            if (Idx >= 400){window.resizeBy(0,-100);
                          decrIdx()};
            
      }

      function checkIdx(){
            if ((getCookie('Txt1') ==                                                             300)){document.getElementById('minusTop').disabled = true;
                        document.getElementById('minusBottom').disabled = true;}
            var W = screen.width;
            W = (W *.89);
            var T = getCookie('Txt1');
            if (T == null){Adj = 300;
                         document.getElementById('minusTop').disabled=true;
                         document.getElementById('minusBottom').disabled=true;}
                         else{Adj = T;}
            if (Adj >= 300){resizeTo(W,Adj);
                        Idx = Adj;}
              else {setCookie('Txt1',300);}      
      }      

      function printTxt(){
            for (var i=1; i<9 ;i++)
                  {document.getElementById(i).style.visibility = "hidden"};
            window.print();
            for (var i=1; i<9 ;i++)
                  {document.getElementById(i).style.visibility = "visible"};
      }
      
      
</script>
</HEAD>
<BODY>
<Table width="650" Border="0" Align="center">
<TR>
      <TD width="33%" align="left">
            <SPAN ID="1">
            <input type="button" value="Print Text" onClick="printTxt()">
            </SPAN>
      </TD>
      <TD Width="33%" align="center">
            <SPAN ID="2"><input type="button" value="+" onclick="longer()"></SPAN>
            <SPAN ID="3"><font class=Blue14> Resize This Window</font></SPAN>
            <SPAN ID="4"><input type="button" id=minusTop value="-"                                     onclick="shorter()"></SPAN>
      </TD>
      <TD Width="33%">&nbsp;</TD>
</TR>
</Table>
<hr>

<H2>History</H2>
<p>Lakewood was originally known as Township 7, Range 14, of Rockport Township.
The settlement became known as East Rockport, and, in 1889 it became the hamlet
known as Lakewood.</p>
<p>Lakewood in the early 1800's was "a great forest ringing Lake Erie." At the
beginning of the 1800's there was no way to go west except over the Indian trail
or by lake, so a road was cut through the forest from Cleveland to the mouth of
the Huron River. By 1812 Cleveland was on its way to becoming a town at the
mouth of the Cuyahoga River and a considerable settlement was established at the
mouth of Rocky River. Until that date no settler was attracted to the land
between. At the age of 20, James Nicholson, Lakewood's first permanent settler,
came west from Connecticut on foot. By 1818 he had acquired over 300 acres from
Madison Avenue to the Lake. In 1835 he erected a white colonial house on the old
Indian trail going west, now known as Detroit Avenue. The building is considered
to be one of the best examples of New England architecture in this area today
and is listed in the National Register. James Nicholson was an earnest,
energetic man, vitally interested in the civic and educational development of
the community.</p>
<p>In the 1830's and 40's log cabins along Detroit
Road were replaced by stone houses because stone was plentiful in the area. The
museum in Lakewood Park is the only stone house remaining from the past. It
contains household goods, implements, and furniture that were common in pioneer
dwellings in the early 19th century.</p>
<p>By the mid-19th century, East Rockport was still agricultural and its
orchards and vineyards were famed for the quality of their fruit. About the only
businessmen were tavern-keepers. After the Civil War, the area began a
transformation that reflected the growing wealth and rapid industrialization
that was taking place in the United States. Simple farm-houses gave way to large
mansions along Detroit Avenue. Churches were built, schools founded, and the
community grew and prospered.</p>
<p>In the 1850's the valley of Rocky River was, as it continues to be today, a
favorite recreation area in the county and did more than anything else to develop
transportation. It inspired the building of the Plank Toll Road over the Detroit
Ridge around Civil War times. The old Rocky River Railroad, nicknamed "The
Dummy," was built in 1869 to bring Clevelanders to Clifton Park, a popular
summer resort. The Dummy Railroad and the Plank Toll Road contributed greatly to
the settlement of Lakewood.</p>
<p>The subdivision of the Clifton Park Allotment started in the 1870's. Clifton
Park, with its winding streets and stately homes, was an enclave of Cleveland's
great industrial families. Clifton Park was designated a landmark in 1975 as a
"unique and worthy area" because of its beautiful homes.</p>
<p>The Rockport School District comprised a large number of subdistricts, each
with their own one room schoolhouse. In 1871 three of these subdistricts voted
to organize into a separate school district. Thus was formed what is now
Lakewood, but was called East Rockport until 1885. In 1879 it was voted to build
a new four room building in the middle of the district. This buiding still
stands on Warren Road and is Lakewood's Recreation office. Over the entrance can
be seen the name "East Rockport Central School 1879." This was the beginning of
what became one of the finest school systems in the state. The Lakewood Public
Schools date from the late 19th and early 20th centuries, with the exception of
Grant School, which was built in the late 1960s. Many of the older school
buildings reflect unique architectural designs.</p>
<p>Toward the end of the 19th Century a great increase in population came about
as a result of developments in transportation. The Plank Toll Toad was taken
over and tolls were abolished. Madison, Clifton and Lake Road had been cut
through and cross streets were opened. Many of the cross streets were named
after Lakewood's early settlers, James Nicholson, Mars Wagar, John Hall and
others. In the 1890s, streetcar lines and railroads extended service to
Lakewood. The population grew from about 450 in 1890 to more than 15,000 by
1910. The orchards and vineyards gradually disappeared as newcomers built homes
on the cross streets. Later, the automobile would complete the transformation of
Lakewood from a farming community to a full-fledged city. In 1911 Lakewood
became a city.</p>
<p>At the turn of the century through the 1920's homes began to spring up all
over the city to keep pace with the rapidly growing population. These homes were
built to last and make Lakewood the interesting, well-established community it
is today. A drive through the tree-lined streets reveals a vast range of housing
types, from small well-kept bungalows to spacious elegant estates.</p>
<p>Although known as a "City of Homes," Lakewood also became the site of
numerous apartment buildings that reflect the architecture of changing times,
from gracious English Tudor to the post-World War II high-rises of the Gold
Coast. During the '20s and '30s, scores of plain two- and three-story brick
buildings with storefronts at the street level and apartments above were built
along Madison and Detroit Avenues.</p>
<p>At the eastern end of the city, a unique neighborhood with the flavor of
Eastern Europe grew up as thousands of immigrants from Central and Eastern
Europe arrived to work in the factories and industries in eastern Lakewood and
west Cleveland. It was nicknamed Birdtown because of street names such as
Plover, Quail and Dove.</p>
<p>Lakewood Hospital, the city's largest employer, opened in 1907 in a wooden
house at Belle and Detroit Avenues with a staff of three doctors and one nurse.
In 1917, the house gave way to a large brick building on Detroit which several
building programs have expanded to the present facility of over 400 beds and
numerous specialized services.</p>
<p>Today the city's population stands at more than 55,000. Lakewood remains a stable, welcoming community with a rich past, vital present and promising future.</p>

<H2>Profile</H2>
<p>U.S. Census 2000 pegged Lakewood's population at
56,646. This tally represents a 5.1% DECREASE  from 1990. Lakewood is the
14th largest city in Ohio and second largest suburb in Cuyahoga County.</p>
<p>21% of Lakewood's population is under age 18. In racial/ethnic
categories census figures show: 52,723 White (93%); 1,116 Black (1.9%); 139 American Indian;
815 Asian; 349 other; 1,504 multi-racial; 1,269 Hispanic.</p>
<p>The 1999 effective residential property tax
is $77.67 per $1,000 of tax valuation. Cuyahoga County
assesses residential property at 35% of the current market value.  The average sale price for a home in
Lakewood for 1999, the latest year for which data is available, was $121,200.
</p>
<p>The income tax
rate is 1.5%.
</p>
<p>According to Census Bureau income data for 1989, the latest year for which such data is available, the median Lakewood household income was $28,791, and the median per capita income was $16,258.
</p>
<p>The total number of dwelling and rooming units, residential and commercial is 28,625, and the average household size is 2.2 persons.
</p>
<p>35 churches represent 14
denominations.
</p>
<p>The school system is comprised of 1 high school,
3 middle schools and 10 elementary schools with an enrollment of 7,860 and a
student/teacher ratio of 24/1.
</p>
<p>Lakewood is recognized for its excellent school system and outstanding city services. Cleveland Magazine (June, 1996) ranked Lakewood as the 5th best suburb overall in its annual survey of 47 Cleveland-area communities. Factors such as education, crime, environment, population density and diversity, poverty level, housing and taxes were considered.  
</p>
<p>Lakewood offers more than 69 acres of
parks, indoor/outdoor ice skating rinks, indoor/outdoor swimming pools, lighted
tennis courts, volleyball and basketball courts, miniature golf, baseball and
softball diamonds, year-round youth and adult programs, soccer field, YMCA, YWCA in addition to
a boat launch in the Metropark adjacent to the city.
</p>
<p>Lakewood is home to approximately 1,000
businesses and government agencies employing over 21,000 people. A downtown
72,000 square foot City Center is home to 15 retail stores. Many unique
specialty and antique shops are located along the major avenues of Madison and
Detroit.
</p>

<H2>Geography</H2>
<p>Lakewood is located along the southern shore of Lake Erie, 5 miles west of Cleveland's Public Square. Lakewood is widely known as the "City of Homes." It offers both the amenities of city living and the charm of a small town. Solidly built one and two-family homes, many with comfortable front porches, line its tree-lined streets. Within Lakewood's 5.6 square miles there is a diversity in housing, from modest single homes to luxury "Gold Coast" condominiums. The northern section of Clifton Park, a residential neighborhood, is listed in the National Register of Historic Places.</p>
<hr>

<Table width="650" Border="0" Align="center">
<TR>
      <TD Width="33%">&nbsp;</TD>
      <TD Width="33%" align="center">
            <SPAN ID="5"><input type="button" value="+" onclick="longer()"></SPAN>
            <SPAN ID="6"><font class=Blue14>Resize This Window</font></SPAN>
            <SPAN ID="7"><input type="button" id=minusBottom value="-"                                     onclick="shorter()"></SPAN>
      </TD>
      <TD Width="33%" align="right">
            <SPAN ID="8"><input type="button" value="Print Text"                                           onclick="printTxt()"></SPAN>
      </TD>      
</TR>
</Table>
<Script> checkIdx() </Script>
</Body>
</HTML>
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 11226864
hi mjhLakewood,
Welcome to Experts-Exchange.   Can you decribe what the above code does, and tell us how it relates to this user's problems?  Thanks!
-- Dan
0
 
LVL 1

Expert Comment

by:mjhLakewood
ID: 11227067
No. I'm sorry. Please forgive me for responding to this request for help. I meant well, but apparently...  Oh,well.   I'll leave it at that.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 11413445
I recommend: points to DanRollins
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now