You are not logged in.

#1 2009-10-06 22:36:53

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

[SOLVED] Render Webpage from CLI to File?

Anyone got any tricks I can use to render a URL directly to a file on the command line?

I have a system setup that will e-mail me a URL occasionally. I want to extract the URL from the e-mail, render the URL into a file, and then print the resulting file (ie, e-mail this address a URL, and that web page will be printed out).

Any ideas?! smile

EDIT: FWIW tha page looks like the below.
firecall.JPG
firecall2.JPG
firecall3.JPG

Last edited by fukawi2 (2009-10-07 02:58:19)

Offline

#2 2009-10-06 22:44:09

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: [SOLVED] Render Webpage from CLI to File?

There's html2txt in community.

-edit-

Hm, probably wouldn't work with graphics. But it should be simple enough to print automagically.

Last edited by lucke (2009-10-06 22:47:11)

Offline

#3 2009-10-06 22:49:39

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] Render Webpage from CLI to File?

maybe curl/wget the html, do some html2pdf magic and print the pdf?

this may be of use:

> aurget -s princexml
aur/princexml 6.0r4-4  [out of date]
    converts XML and HTML into PDF documents using the css print spec

how limited are you? i mean, you could easily script uzbl to open/print the page (even if its in an X session you can't see...)

Offline

#4 2009-10-06 23:53:29

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: [SOLVED] Render Webpage from CLI to File?

Still have the problem of the images / maps though... Any ideas on how to handle them from a text based environment? hmm

Offline

#5 2009-10-07 00:07:28

Knute
Member
From: Minot, ND
Registered: 2009-03-17
Posts: 604

Re: [SOLVED] Render Webpage from CLI to File?

fukawi2 wrote:

Still have the problem of the images / maps though... Any ideas on how to handle them from a text based environment? hmm

If you are completly text based and looking for graphics, I would suggest that you setup a framebuffer, and then use w3m with framebuffer support, and you should be good.


Knute

Offline

#6 2009-10-07 00:08:07

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: [SOLVED] Render Webpage from CLI to File?

If you convert it to pdf and then use lpr or somesuch to print the pdf file, it should work. Can't really test it now.

Offline

#7 2009-10-07 01:44:47

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: [SOLVED] Render Webpage from CLI to File?

Knute wrote:

If you are completly text based and looking for graphics, I would suggest that you setup a framebuffer, and then use w3m with framebuffer support, and you should be good.

I don't need to view the graphics though, just render them into a file and send to the printer.

This is actually a lot more complicated than I thought it may be... The maps aren't just images, they're actual Google Maps :s

<title>19FIRE Map</title>
        <script src="http://maps.google.com/?file=api&v=2.x&key=ABQIAAAAW7DqHnhVYuKoFjBvZM-UKxTQsGcO0LneRX5C_-o5Fzlp0hMKjxSLomgw7CSUIXa9iM3qpxCGyXu88Q" type="text/javascript"></script>
        <script type="text/javascript">
            var routeMap;
            var gdir;
            var situationMap;
            function initialize() {
                if(GBrowserIsCompatible()){
                    routeMap = new GMap2(document.getElementById("route_map"));
                    routeMap.setUIToDefault();
                    gdir = new GDirections(routeMap, document.getElementById("directions"));
                    GEvent.addListener(gdir, "error", handleErrors);
                    gdir.load("from: -37.977600,145.206818 to: -37.980433,145.183873");
                    situationMap = new GMap2(document.getElementById("situation_map"));
                    situationMap.setCenter(new GLatLng(-37.980433, 145.183873), 17);
                    situationMap.addOverlay(new GMarker(new GLatLng(-37.980433, 145.183873)));
                    situationMap.setUIToDefault();
                }
            }
            function handleErrors(){
                if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
                    alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
                else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
                    alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
                else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
                    alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
                else if (gdir.getStatus().code == G_GEO_BAD_KEY)
                    alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
                else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
                    alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
                else alert("An unknown error occurred.");
            }
        </script>
    </head>
    <body onload="initialize()" onunload="GUnload()">
        <h1>19FIRE Incident F091002302</h1>
......
        <table class="directions">
            <tr><th>Route Map</th></tr>
            <tr>
                <td>
                    <div id="route_map" style="width: 512px; height: 512px"> </div>
                </td>
            </tr>
            <tr><th>Formatted Directions</th></tr>
            <tr>
                <td>
                    <div id="directions" style="width: 512px"></div>
                </td>
            </tr>
            <tr><th>Situation Map</th></tr>
            <tr>
                <td>
                    <div id="situation_map" style="width: 512px; height: 512px"> </div>
                </td>
            </tr>

Offline

#8 2009-10-07 02:03:55

Knute
Member
From: Minot, ND
Registered: 2009-03-17
Posts: 604

Re: [SOLVED] Render Webpage from CLI to File?

This topic just stuck in my head for some reason, so I searched the aur and found wkhtmltopdf.   It's supposed to convert an html to a pdf file.   I haven't tried it, but here are the sites:

http://aur.archlinux.org/packages.php?ID=26065
http://code.google.com/p/wkhtmltopdf/

There was another one called pisa, but that was flagged as out of date.
FYI... I used the search term "render" if you want to look thru the results.  The two that I mentioned looked closest to what you were looking for, though.

HTH,


Knute

Offline

#9 2009-10-07 02:57:17

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: [SOLVED] Render Webpage from CLI to File?

Oh yeah... You da man Knute big_smile

wget -O - 'http://<URL>.html' | wkhtmltopdf --no-background --page-size A4 --margin-top 20 --margin-bottom 20 --margin-left 24 - fireMap.pdf

Results in this file: http://fukawi2.nl/~fukawi2/fireMap.pdf

I can handle getting the PDF to the printer no problems.

Thanks heaps Knute!

Offline

#10 2009-10-07 03:05:21

Knute
Member
From: Minot, ND
Registered: 2009-03-17
Posts: 604

Re: [SOLVED] Render Webpage from CLI to File?

You are most welcome.


Knute

Offline

#11 2009-10-07 14:30:56

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] Render Webpage from CLI to File?

are you serious!!! i had the wget > html > pdf solution at post #3!!!

i'm not bitter or anything...

tongue

glad you've solved it, i'm gonna go add a bash function real quick too.

Offline

#12 2009-10-07 22:05:47

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: [SOLVED] Render Webpage from CLI to File?

brisbin33 wrote:

are you serious!!! i had the wget > html > pdf solution at post #3!!!

Sorry, I worked backwards through the suggested solutions, and stopped when I found one that worked tongue

You should have been slower tongue

Offline

Board footer

Powered by FluxBB