save current web page as pdf

139 views
Skip to first unread message

brainless

unread,
May 12, 2008, 6:23:21 PM5/12/08
to Watir General
I posted this same question on another forum and I got no reply. So
I'm trying it here.

I’m new to Ruby. I’m looking for ways to submit web forms and save the
resulting web page in a pdf file.

So I go to https://www.some-site.com (yes https); I click on a “start”
button and a new page with a form to fill is displayed; I fill in the
form using data from a csv file; I click on a button to submit the
form; a new confirmation page is displayed. I want to save this
confirmation page in a pdf file.

I want to do this in Windows using simple Ruby scripts (without AJAX
or RAILS or VB, etc.) Using just Ruby scripts, Watir and IE 6, I am
able to do the form submit and navigation. I have no problem reading
from csv and navigating the website. However, I can’t seem to find a
simple way to save the last page into a pdf file.

I tried using the IE “print” function (CTRL-P) but I can only get the
IE print dialog to come up; I don’t know how to supply the file name
for the pdf printer’s “save as” pop-up window. Maybe CTRL-P is not the
way to do this.

Any ideas?

Thanks.
brainless

Alister Scott

unread,
May 12, 2008, 11:47:03 PM5/12/08
to Watir General
Hi,
Are you trying to manually check that the page displays correctly?
I don't know of a way to save as PDF using Watir.
Four alternative options:
1) Capture screen image of page - see example unit test called
screen_capture_test.rb in your Watir gem directory.
2) Capture screen of image (scrollable) using Snagit (not freeware) -
see example:
http://groups.google.com/group/watir-general/browse_thread/thread/844f9ee827b8e82/9b8a239e551dd5df?lnk=gst&q=snagit#9b8a239e551dd5df
3) Capture html source of page and save as html file - it won't
include images and stylesheets though.
4) Ask your developers to include functionality that generates a PDF
file of the page as a link, which you can just save to disk.

Cheers,

Alister Scott
Brisbane, Australia
http://watirmelon.wordpress.com

On May 13, 8:23 am, brainless <brainless1der...@yahoo.com> wrote:
> I posted this same question on another forum and I got no reply. So
> I'm trying it here.
>
> I’m new to Ruby. I’m looking for ways to submit web forms and save the
> resulting web page in a pdf file.
>
> So I go tohttps://www.some-site.com(yes https); I click on a “start”

Bret Pettichord

unread,
May 13, 2008, 2:00:07 PM5/13/08
to watir-...@googlegroups.com
I suggest using Autoit for the missing pieces. Watir uses this tool
sometimes itself.

Bret

andy sipe

unread,
May 14, 2008, 8:35:20 AM5/14/08
to watir-...@googlegroups.com
Another thing I've used in the past is PDFCreator. It is a PDF print
driver. Depending on what you are trying to do you might be able to
automate the printing and then configure PDFCreator to save the output
and use it however you wish. You may have to use a bit of Windows
automation (autoit, etc..) to pull this off.

-andy

--

----------------------------------------------------
Andy Sipe
http://zbarzone.blogspot.com/
----------------------------------------------------

marekj

unread,
May 14, 2008, 12:32:58 PM5/14/08
to watir-...@googlegroups.com
brainless,
do you want to send to page to the printer? (by printer I mean Print to .... printer or PDF or T-shirt) or do you want to capture the screenshot?

For PDF I would use autoit probably as Bret suggested and for screenshots I started using snagit automation.

On windows I use doPDF drivers http://www.dopdf.com/
Here are some notes on screenshots
http://www.marekj.com/2008/04/21/desktop-screenshots-with-watir-win32screenshot-and-rmagick/


--
marekj

www.testr.us | semantic test objects modeling in watir

aidy lewis

unread,
May 14, 2008, 12:38:30 PM5/14/08
to watir-...@googlegroups.com
On 14/05/2008, marekj <marek...@gmail.com> wrote:
> For PDF I would use autoit probably as Bret suggested and for screenshots I
> started using snagit automation.
>

Watir has a screenshot library. I also wrote something on the Watir
faq about creating screenshots and sending them to Word.

http://wiki.openqa.org/display/WTR/FAQ

--
Aidy
www.agiletester.co.uk

marekj

unread,
May 14, 2008, 12:54:06 PM5/14/08
to watir-...@googlegroups.com
Aidy, yes, you can take screenshots with PRINTSCREEN but I needed to webpage scrolling and I needed to save them as small png files so sngit automation fits my need.
Thanks

On Wed, May 14, 2008 at 11:38 AM, aidy lewis <aidy....@googlemail.com> wrote:
Reply all
Reply to author
Forward
0 new messages