Automating firefox

View: New views
12 Messages — Rating Filter:   Alert me  

Automating firefox

by Michael Cohen-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello wise linux gurus.

I have a need in my web application to generate some pdfs from html
pages. I looked around the net and found lots of little scripts but
none produces anywhere near the quality that I need. I want to get a
near true replication o f the web page which means that it needs to
parse css properly, insert images etc. Unfortunately the users use
Internet exploder which is really crap for printing.

I looked on the net and this http://www.princexml.com/purchase/ looks
good but its prohibitively expensive (almost $5k - wow). Its output is
not too bad but not quite perfect still as it tried to create pdf
forms from html forms (so it doent look exactly like the web page).

I tried firefox and if you turn on the option file/page setup/print
background color and images it works very well and produces excellent
postscript which I can easily export to pdf. This is ideal but now i
have the problem of how do i automate this?

Ideally I would like to be able to call firefox from the command line
to print as a one off job (giving it a url as an arg). I dont think
its supported. Next I could try running it in a virtual X server and
programmatically clicking buttons on it - does anyone have any idea
how to do this? This is similar to GDI automation under windows - im
sure there is a way to do it under linux, i vaguely recall tridge
talking about it a while back in a clug meeting but I cant find any
leads...

Any help would be appreciated.

Michael.
--
linux mailing list
linux@...
https://lists.samba.org/mailman/listinfo/linux

Re: Automating firefox

by Bugzilla from bradh@frogmouth.net :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Monday 14 January 2008 12:34:32 am Michael Cohen wrote:
> I have a need in my web application to generate some pdfs from html
> pages. I looked around the net and found lots of little scripts but
> none produces anywhere near the quality that I need. I want to get a
> near true replication o f the web page which means that it needs to
> parse css properly, insert images etc.
Does it render correctly under Konqueror? If so, you can probably automate it
with dcop to do what you want.

Brad

--
linux mailing list
linux@...
https://lists.samba.org/mailman/listinfo/linux

Re: Automating firefox

by Andrew Janke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> I have a need in my web application to generate some pdfs from html
> pages. I looked around the net and found lots of little scripts but
> none produces anywhere near the quality that I need. I want to get a
> near true replication o f the web page which means that it needs to
> parse css properly, insert images etc. Unfortunately the users use
> Internet exploder which is really crap for printing.
>
> I looked on the net and this http://www.princexml.com/purchase/ looks
> good but its prohibitively expensive (almost $5k - wow). Its output is
> not too bad but not quite perfect still as it tried to create pdf
> forms from html forms (so it doent look exactly like the web page).
>
> Ideally I would like to be able to call firefox from the command line
> to print as a one off job (giving it a url as an arg). I dont think
> its supported. Next I could try running it in a virtual X server and
> programmatically clicking buttons on it - does anyone have any idea
> how to do this? This is similar to GDI automation under windows - im
> sure there is a way to do it under linux, i vaguely recall tridge
> talking about it a while back in a clug meeting but I cant find any
> leads...

There is a thing called firefox-remote that will at least open a page
IIRC but it doesnt do all you want.

To get the extra keypress's you could take the X11 route ala this:

   http://www.doctort.org/adam/nerd-notes/x11-fake-keypress-event.html

And just send a Ctrl-P, TAB, Space, etc etc.  Then instead of
converting the PS to PDF just use the CUPS PDF driver.


a
--
linux mailing list
linux@...
https://lists.samba.org/mailman/listinfo/linux

Re: Automating firefox

by Andrew Janke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> To get the extra keypress's you could take the X11 route ala this:
>
>    http://www.doctort.org/adam/nerd-notes/x11-fake-keypress-event.html

OO-er! scratch that here is a much nicer way.

   http://search.cpan.org/~ecalder/X11-SendEvent-1.3/SendEvent.pm

Seems that I must waste some time now trying it.. :)


a
--
linux mailing list
linux@...
https://lists.samba.org/mailman/listinfo/linux

Re: Automating firefox

by Tony Lewis-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Next I could try running it in a virtual X server and
> programmatically clicking buttons on it - does anyone have any idea
> how to do this?

I've heard of, but not used, xautomation - http://hoopajoo.net/projects/xautomation.html - which can even visually grep for images, so you can make sure you click on the right button.

If you try it, please report back how it went for you.  It's one of those things I think I might need in the future.

Tony

--
linux mailing list
linux@...
https://lists.samba.org/mailman/listinfo/linux

Re: Automating firefox

by Sam Couter-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Michael Cohen <scudette@...> wrote:
> I have a need in my web application to generate some pdfs from html
> pages.

If you control the web application, you can include JavaScript to do
what you want.

An alternative is to use a proxy server that injects JavaScript. See
Selenium (http://www.openqa.org/selenium/) for an example. It's
implemented in Java, but it drives browsers using JavaScript.
--
Sam Couter         |  mailto:sam@...
                   |  jabber:sam@...
OpenPGP fingerprint:  A46B 9BB5 3148 7BEA 1F05  5BD5 8530 03AE DE89 C75C


--
linux mailing list
linux@...
https://lists.samba.org/mailman/listinfo/linux

signature.asc (196 bytes) Download Attachment

Re: Automating firefox

by Michael Cohen-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sam how would this work? As far as I can tell in js you can issue a
window.print() which brings up the print dialog but you can not
actually submit it due to the js security model. Neither can you
select the output filename. Am i far off the mark?

So far i have been playing with the many suggestions on this thread. I
found Xnee which seems sort of able to do what I want except that
there is no way to tell it which windows to target. Most solutions
seem to be flying blind - injecting keystrokes with very little
feedback about which window they are using. Maybe I will patch xnee to
address keystrokes at named windows which would make it more robust
(in case firefox lost focus for some reason).

I think its definitely doable though,
Michael.

2008/1/14 Sam Couter <sam@...>:

> Michael Cohen <scudette@...> wrote:
> > I have a need in my web application to generate some pdfs from html
> > pages.
>
> If you control the web application, you can include JavaScript to do
> what you want.
>
> An alternative is to use a proxy server that injects JavaScript. See
> Selenium (http://www.openqa.org/selenium/) for an example. It's
> implemented in Java, but it drives browsers using JavaScript.
> --
> Sam Couter         |  mailto:sam@...
>                    |  jabber:sam@...
> OpenPGP fingerprint:  A46B 9BB5 3148 7BEA 1F05  5BD5 8530 03AE DE89 C75C
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFHiyFJhTADrt6Jx1wRAiIrAJ9cP7+EoUaxiLaxBHpCvCP24qQqmgCffM48
> kTvHW+wqJmutJ8Eqm8XplAg=
> =kIWr
> -----END PGP SIGNATURE-----
>
> --
> linux mailing list
> linux@...
> https://lists.samba.org/mailman/listinfo/linux
>
>
--
linux mailing list
linux@...
https://lists.samba.org/mailman/listinfo/linux

Re: Automating firefox

by Sam Couter-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Michael Cohen <scudette@...> wrote:
> Sam how would this work? As far as I can tell in js you can issue a
> window.print() which brings up the print dialog but you can not
> actually submit it due to the js security model. Neither can you
> select the output filename. Am i far off the mark?

I'm afraid you've exceeded my knowledge, but I'd be surprised if you
were wrong. Printing with no user input is a dead tree and an empty
expensive ink cartridge waiting to happen.

How much control do you have over the deployment of Firefox? Can you
arrange for a plugin to be installed? I don't think they're constrained
by the same security model. You may be able to control the print dialog.

Here's a couple of Firefox config items to check out:

( from http://gentoo-wiki.com/HOWTO_Integrate_Firefox_with_KDE )
print.printer_PostScript/Default.print_command
print.always_print_silent

--
Sam Couter         |  mailto:sam@...
                   |  jabber:sam@...
OpenPGP fingerprint:  A46B 9BB5 3148 7BEA 1F05  5BD5 8530 03AE DE89 C75C


--
linux mailing list
linux@...
https://lists.samba.org/mailman/listinfo/linux

signature.asc (196 bytes) Download Attachment

Re: Automating firefox

by Bugzilla from bradh@frogmouth.net :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Monday 14 January 2008 06:44:04 am Brad Hards wrote:
> On Monday 14 January 2008 12:34:32 am Michael Cohen wrote:
> > I have a need in my web application to generate some pdfs from html
> > pages. I looked around the net and found lots of little scripts but
> > none produces anywhere near the quality that I need. I want to get a
> > near true replication o f the web page which means that it needs to
> > parse css properly, insert images etc.
>
> Does it render correctly under Konqueror? If so, you can probably automate
> it with dcop to do what you want.
Here is how:
Set up a default printer (i.e. the print to PDF), then do:

myref=`dcopstart konqueror`
dcop $myref konqueror-mainwindow\#1 openURL "http://www.clug.org.au"
dcop $myref html-widget1 print true

Then move the output file.

Brad

--
linux mailing list
linux@...
https://lists.samba.org/mailman/listinfo/linux

Re: Automating firefox

by Adam Jenkins-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


What do you use to convert to PDF?  I find that ps2pdf gives me pretty
lousy results, at least on the web pages I've been trying..

--
linux mailing list
linux@...
https://lists.samba.org/mailman/listinfo/linux

Re: Automating firefox

by Michael Cohen-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,
  It has been some time, but I would like to thank all who replied to
this thread. Especially Brad Hards whos konqueror solution won out. I
found the python-dcop bindings and am running konqueror in a
vncsession (just so I can connect and interact with it if needed). The
result is very good, except that I could not figure a way to know when
the page has finished rendering so Its a little slow with a big fat
sleep between the openurl and the print call.

Its a little rough but got me out of trouble.

Thanks,
Michael.

On Mon, Jan 14, 2008 at 9:08 PM, Brad Hards <bradh@...> wrote:

> On Monday 14 January 2008 06:44:04 am Brad Hards wrote:
>  > On Monday 14 January 2008 12:34:32 am Michael Cohen wrote:
>  > > I have a need in my web application to generate some pdfs from html
>  > > pages. I looked around the net and found lots of little scripts but
>  > > none produces anywhere near the quality that I need. I want to get a
>  > > near true replication o f the web page which means that it needs to
>  > > parse css properly, insert images etc.
>  >
>  > Does it render correctly under Konqueror? If so, you can probably automate
>  > it with dcop to do what you want.
>  Here is how:
>  Set up a default printer (i.e. the print to PDF), then do:
>
>  myref=`dcopstart konqueror`
>  dcop $myref konqueror-mainwindow\#1 openURL "http://www.clug.org.au"
>  dcop $myref html-widget1 print true
>
>  Then move the output file.
>
>
>
>  Brad
>
>  --
>  linux mailing list
>  linux@...
>  https://lists.samba.org/mailman/listinfo/linux
>
--
linux mailing list
linux@...
https://lists.samba.org/mailman/listinfo/linux

VNC Connection

by Pilcher, Fred :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This isn't a strictly a Linux-related question, but I hope someone has
some ideas.

I've recently converted a friend from Windows to Kubuntu. To help with a
few configuration issues (the blind leading the even more blind) I
connected to her PC via VNC using krdc/krfb and all went well. A couple
of nights ago we needed to do it again to work through some stuff, but
couldn't.  

When we'd successfully connected earlier she had to put her PC into her
DMZ but last night, as soon as she did that her modem stopped responding
to pings, though she could ping me. When she moved out of the DMZ, her
modem responded to pings again. We tried it several times and the result
was consistent every time. Regardless of whether she was in the DMZ or
not, krfb on her end didn't indicate that I was trying to connect, and
krdc on my end just sat there waiting for a response from her PC.

If it hadn't worked previously I'd simply assume that I was just too
ignorant to do it. And the behaviour of her modem when she moved the PC
in and out of the DMZ just sounds weird.

She hadn't changed any settings since we'd connected successfully. I
could connect to other PCs on my home network using krdc/krfb. She's on
an ADSL connection via Netspeed and I'm on a cable connection via
Transact/Netspeed if that has any relevance.

Does anyone have any ideas?

Thanks,

Fred
 
-----------------------------------------------------------------------
This email, and any attachments, may be confidential and also privileged. If you are not the intended recipient, please notify the sender and delete all copies of this transmission along with any attachments immediately. You should not copy or use it for any purpose, nor disclose its contents to any other person.
-----------------------------------------------------------------------
--
linux mailing list
linux@...
https://lists.samba.org/mailman/listinfo/linux