BUU has asked for the wisdom of the Perl Monks concerning the following question:

Basically I have a chunk of html and I would like to render it and then measure it. The only think I can think up off the top of my head is to do something like get the mozilla html renderer and some how pass it args or something? I would prefer to do this in perl, which is why I'm asking here. Anyways, anyone have any ideas?
  • Comment on Seeking ideas for measuring rendered html size

Replies are listed 'Best First'.
Re: Seeking ideas for measuring rendered html size
by sauoq (Abbot) on Jun 10, 2003 at 23:27 UTC

    I don't even really see how this makes sense. I guess it makes a little eensy-weensy bit o' sense if everything on the page is absolutely positioned and sized, but the size of rendered HTML is really a function of the browser. You could, for instance, "render" it with lynx -dump and count the lines.

    How do you take into account the user's screen size and resolution? Or whether they resize the browser window? Or use custom styles? Etc.

    You should probably be asking yourself if you really need to do this.

    -sauoq
    "My two cents aren't worth a dime.";
    
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Seeking ideas for measuring rendered html size
by grantm (Parson) on Jun 11, 2003 at 09:28 UTC

    Ok, this whole thing makes about as much sense to me as it seems to be making to everyone else but here's an approach that might work.

    1. write the HTML out to file 'X' but before you do that, add a JavaScript function (triggered by onLoad) and wrap the body of the page in a div with an id 'Y'
    2. have your script fire up a browser and on its command line give it the URL of file 'X'
    3. when the JavaScript function is called, have it query the height and width properties of div 'Y' and submit these details to a CGI script
    4. have the CGI script signal your original script that it's all over and the browser process can be killed.

    With Mozilla remoting, you can instruct an already running browser process to load a particular URL so I guess you could skip steps 2 and 4. Step 1 could be done on the fly by a CGI script. You could use CSS to set the width of div 'Y' to be fixed and then measure the height.

Re: Seeking ideas for measuring rendered html size
by waswas-fng (Curate) on Jun 10, 2003 at 23:47 UTC
    Not to mention many browsers let you resize by percentage on the fly -- size is relitive. What are you trying to do? What is the actual usable output that you are looking for.

    -Waswas
Re: Seeking ideas for measuring rendered html size
by Aristotle (Chancellor) on Jun 11, 2003 at 09:59 UTC
    Use PDF or Postscript documents instead.

    Makeshifts last the longest.

Re: Seeking ideas for measuring rendered html size
by Elian (Parson) on Jun 11, 2003 at 17:27 UTC
    As many people have already pointed out, the 'actual' size of a page depends on the browser, the user's browser preferences, the user's display resolution, the system installed fonts, the display preferences, the user's OS platform, the font aliasing preferences, and the user's browser window size. Occasionally it depends on the phase of the moon, but only at high tide or when pluto is in the House of Aquarius.

    HTML doesn't define presentation at all, and HTML with CSS makes really strong suggestions about presentation, but still doesn't define it exactly. (Assuming any browser actually completely and accurately implements the CSS specs, which none do. (Not even counting the spots in the CSS specification that aren't exact enough to definitively render))

    The best you're going to be able to do is make a 90% guess. Using an existing rendering engine would be the way to do this, but if you're going to use the result to influence the design as presented to other people, you're probably better off using the IE/Windows HTML rendering engine, as it disagrees with Mozilla on quite a few things and, like it or not, is significantly more used. (And no, I have no idea how you'd do this)

Re: Seeking ideas for measuring rendered html size
by benn (Vicar) on Jun 11, 2003 at 17:02 UTC
    Another way may be using something like wxPerl...I'm only guessing, but looking at the docs, it looks like it should be possible. wxHTMLWindow sets its *height* (you specify the width on creation) based on its rendered HTML, and you should then be able to use wxScrolledWindow::GetVirtualSize() to determine this.

    Cheers, Ben.

Re: Seeking ideas for measuring rendered html size
by Theo (Priest) on Jun 11, 2003 at 14:31 UTC
    I'm more than a little confused. My first thought was that you wanted the size of the file in bytes, but the following dicussion doesn't bear that out. Perhaps you could mention what sort of "measure it" you're refering to: inches, pixels, %of screen width, ... Some of the monks might be able to derive a better solution if you could breifly say why this is a need and where you want this info: for your eyes only, part of the HTML page, info with which to better render the page, etc.

    -ted-

Re: Seeking ideas for measuring rendered html size
by shotgunefx (Parson) on Jun 11, 2003 at 20:03 UTC