Interested in a gecko (Firefox)-based equivalent?

704 views
Skip to first unread message

hatton

unread,
Jul 31, 2013, 12:43:26 PM7/31/13
to wkhtmltop...@googlegroups.com
Our open-source program uses wkhtmltopdf, and it works well. However we have customers that need a "smart font" complex script support that is only available in Firefox (gecko). We also would like access to the very latest CSS enhancements. It turns out that FF/Gecko can produce PDFs. So we're experimenting with swapping out wkhtmltopdf for something based on gecko. Our project is done in c#, using geckofx. We may just embed this in our app, with no external exe, so it wouldn't be of use to others.

I'm wondering if there would be sufficient interest to warrant making a separate open source project, similar to wkhtmltopdf, but using this .net/mono/geckfox approach? By ourselves, we aren't going to be implementing most of what's in wkhtmltodpf; no headers, table of contents, etc. Just plain 'ol rendering of the html. But maybe others would like to add those things, even just paralleling the wkhtmltopdf command line? If that sounds like a project you'd contribute to, please get in touch with me.

jh

Kees van Spelde

unread,
Jul 31, 2013, 1:53:36 PM7/31/13
to wkhtmltop...@googlegroups.com
Hi,

About which gecko opensource project are talking? The only one that I found is this one --> http://code.google.com/p/geckofx/

But that one is old, the last revision is from 2009.

Greetings,
KvS

Op woensdag 31 juli 2013 18:43:26 UTC+2 schreef hatton het volgende:

John Hatton

unread,
Jul 31, 2013, 2:58:40 PM7/31/13
to wkhtmltop...@googlegroups.com
> About which gecko opensource project are talking?

The .net/mono gecko project we use is at https://bitbucket.org/geckofx . It
is active (now up to Firefox 22).

jh


Yozons eSignForms

unread,
Jul 31, 2013, 3:16:25 PM7/31/13
to wkhtmltop...@googlegroups.com
We're not able to help on the coding side, but I think we'd consider using your project if it works as well as wkhtmltopdf.  We, too, pretty much just need it to convert the HTML to PDF without doing any special PDF things, though we do make use of submitting multiple HTML documents to have them all merged into a single PDF.

We love wkhtmltopdf, and it's worked pretty well for us, but the project has stalled with no releases in years despite improvements in rendering engines.

Kees van Spelde

unread,
Aug 1, 2013, 7:34:32 AM8/1/13
to wkhtmltop...@googlegroups.com
Hi,

Is it true that you need firefox installed for geckofx to work? Or can you do without it. Installing firefox on a server is a big no no in our company.

Greetings,
KvS

Op woensdag 31 juli 2013 20:58:40 UTC+2 schreef hatton:

John Hatton

unread,
Aug 1, 2013, 1:19:38 PM8/1/13
to wkhtmltop...@googlegroups.com
>Is it true that you need firefox installed for geckofx to work? Or can you
do without it. Installing firefox on a server is a big no no in our company.

Applications that use geckofx do not rely on Firefox. They embed the actual
engine (it's called xulrunner). Just like wkhtmltopdf comes with webkit.

(It is technically possible to use the installed Firefox, but then you'd
have to ensure that the user had the exact version geckofx was built for,
which would be a disaster as soon as is FF upgraded.)

jh

Kees van Spelde

unread,
Aug 1, 2013, 2:17:22 PM8/1/13
to wkhtmltop...@googlegroups.com
Hi,

I already found xulrunner on the mozilla website. Do you know if it is possible to use xulrunner without a gui? I've build a webservice some years ago and integrated wkhtmltopdf.exe into that (by calling the exe and getting the returned file). I want to do something similar with geckofx, I want to integrate it into a console app. Do you need a form handle for xulrunner or can you do without it?

Greetings,
KvS

Op donderdag 1 augustus 2013 19:19:38 UTC+2 schreef hatton:

John Hatton

unread,
Aug 1, 2013, 2:40:45 PM8/1/13
to wkhtmltop...@googlegroups.com

> I want to do something similar with geckofx, I want to integrate it into a console app.

 

Right, that’s the topic of this thread… the idea of building a console app using geckofx. If you want to do it yourself, you could look at the geckofx unit tests and see how they work without a form onscreen.

 

jh

Kees van Spelde

unread,
Aug 2, 2013, 8:31:45 AM8/2/13
to wkhtmltop...@googlegroups.com
I'm ok with giving it a go... I sure would use it and are willing to build it.

Just needs some ideas about how and what to include.

Op donderdag 1 augustus 2013 20:40:45 UTC+2 schreef hatton:

Kees van Spelde

unread,
Aug 2, 2013, 2:48:43 PM8/2/13
to wkhtmltop...@googlegroups.com
Hatton,

Do you meaby have some example code about how to print a loaded html file to pdf?
I found some example code in the wiki pages from geckofx. But I tried it by always am getting a "object reference not set to an instance of an object" error.

It should be handy for me to have some code to start with.

Greetings,
KvS


Op donderdag 1 augustus 2013 19:19:38 UTC+2 schreef hatton:
>Is it true that you need firefox installed for geckofx to work? Or can you

John Hatton

unread,
Aug 2, 2013, 2:54:29 PM8/2/13
to wkhtmltop...@googlegroups.com

Kvs,

It’s probably going to be cheaper for me to write a working system for you and then let you expand on that. I see if I can hack out something during a trip this coming week.

jh

Kees van Spelde

unread,
Aug 2, 2013, 4:44:46 PM8/2/13
to wkhtmltop...@googlegroups.com
Hi,

I already figured out the error, it prints now but now I'm getting an empty PDF. So a working example would be really nice.

Greetings,
KvS

Op vrijdag 2 augustus 2013 20:54:29 UTC+2 schreef hatton:

Kees van Spelde

unread,
Aug 5, 2013, 9:16:22 AM8/5/13
to wkhtmltop...@googlegroups.com
Hi,

I'm wondering if GeckoFx is the way to go. The fact at this moment:

I use the following code to generate a pdf (example from GeckoFx wiki page)

                nsIWebBrowserPrint print = Xpcom.QueryInterface<nsIWebBrowserPrint>(browser.Window.DomWindow);
                var ps = new PrintSettings();
                ps.SetPrintSilentAttribute(true);
                ps.SetPrintToFileAttribute(true);
                ps.SetShowPrintProgressAttribute(false);
                ps.SetOutputFormatAttribute(2); //2 == PDF
                ps.SetToFileNameAttribute("d:\\temp.pdf");
                ps.SetPrintBGImagesAttribute(true);
                ps.SetStartPageRangeAttribute(1);
                ps.SetEndPageRangeAttribute(100);
                ps.SetPrintOptions(2, true); // evenPages
                ps.SetPrintOptions(1, true); // oddpages
                ps.SetEffectivePageSize(768 * 20f, 1024 * 20f);
                ps.SetShrinkToFitAttribute(true);
                ps.SetScalingAttribute(1.0);
                ps.SetPrintBGImagesAttribute(true);
                ps.SetPlexNameAttribute("duplex");
                ps.SetPrintFrameTypeAttribute(1);
                print.Print(ps, null);

- When I run this code on Windows 8 it won't work (crash or blank PDF)
- When I run this code on Windows XP it works but the links in the PDF are not clickable and it seems CSS is not supported. I see a website in the PDF as if there is no CSS (with other words ... UGLY)
- When I look onto google people say it is not possible to use CSS when printing to PDF.

Greetings,
KvS

Op vrijdag 2 augustus 2013 22:44:46 UTC+2 schreef Kees van Spelde:

John Hatton

unread,
Aug 5, 2013, 9:35:49 PM8/5/13
to wkhtmltop...@googlegroups.com
>- When I look onto google people say it is not possible to use CSS when printing to PDF.

That’d be kind of worthless, wouldn’t it, for Mozilla to add a PDF function that dropped CSS ☺ CSS works fine, but note that Webkit and Gecko do appear to have different expectations for the "file://" prefix, so if your css isn't working, look into that. The white text problem on some machines had us stumped too for a while; the solution is to set "gfx.direct2d.disabled" to true.

But this isn’t the list to be working on code for another project, so let’s just end this thread with a pointer to the new project, which is here: https://github.com/hatton/geckofxHtmlToPdf. I welcome pull requests. For non c# programmers, I’ll post to this list when things have progressed enough to offer a compiled version for people to try out.

jh

Kees van Spelde

unread,
Aug 6, 2013, 1:03:18 AM8/6/13
to wkhtmltop...@googlegroups.com
I agree... I joined Github so I can have a look into geckofxHtmlToPdf.

Wouldn't be gkHtmlToPdf be a nicer name? Gk for GeckoFx and wk for webkit :-)

Greetings,
KvS

Op dinsdag 6 augustus 2013 03:35:49 UTC+2 schreef hatton:

Kees van Spelde

unread,
Aug 6, 2013, 1:06:49 AM8/6/13
to wkhtmltop...@googlegroups.com
Any idea how I can join geckfxHtmlToPdf? I'm rather a newbie in github use.

Op dinsdag 6 augustus 2013 07:03:18 UTC+2 schreef Kees van Spelde:

Open eSignForms

unread,
Aug 6, 2013, 1:05:14 PM8/6/13
to wkhtmltop...@googlegroups.com
Do you have a discussion forum for the gecko solution?  I personally would love to have it work submitting one or more HTML files to create a combined PDF as this is a common feature we use now in wkhtmltopdf.

John Hatton

unread,
Aug 7, 2013, 10:31:17 AM8/7/13
to wkhtmltop...@googlegroups.com
>Do you have a discussion forum for the gecko solution? I personally would
love to have it work submitting one or more HTML files to create a combined
PDF as this is a common feature we use now in wkhtmltopdf.

There's no forum yet, and no compiled release yet. I see you added it to the
issues on github, that's a good idea. I should be clear about expectations,
though. The only features that I personally will be able to deliver for free
are those that my other project needs, which are: graphite smart fonts,
control over page size, orientation, margins, & media query. But the github
approach makes it easy for experienced developers to "fork" a project and
then submit "pull requests" back to the main project. So if your business
would derive value from a new feature, you can get me or someone else to add
it.

jh

Kees van Spelde

unread,
Aug 9, 2013, 3:00:13 PM8/9/13
to wkhtmltop...@googlegroups.com
Hatton,

I don't think there is a way on github to send E-mails so I'm doing it this way.
I optimized your latest code a little bit.

Can you change the following function to the code below and set the oncheckforbrowser... time delay on 5 milliseconds instead of 3000.... it is muuuuuuuuchhhhhhhhhhhhh faster this way ;-)

        private void OnCheckForBrowserNavigatedTimerTick(object sender, EventArgs e)
        {
            if (!_browser.IsBusy && !_browser.IsAjaxBusy)
            {
                _checkForBrowserNavigatedTimer.Enabled = false;
                StartMakingPdf();
            }
        }

Op woensdag 7 augustus 2013 16:31:17 UTC+2 schreef hatton:

Kees van Spelde

unread,
Aug 9, 2013, 4:00:28 PM8/9/13
to wkhtmltop...@googlegroups.com
Even better... change it to this.. readystate seems to werk perfect.


        private void OnCheckForBrowserNavigatedTimerTick(object sender, EventArgs e)
        {
            _checkForBrowserNavigatedTimer.Enabled = false;
            if (_browser.Document.ReadyState == "complete")
                StartMakingPdf();
            else
                _checkForBrowserNavigatedTimer.Enabled = true;
        }

Als remove //_browser.ConsoleMessage += OnBrowserConsoleMessage; ... this makes almost all webpages terribly slooooooooooooooowwwwwwwwwwwwwwwwwwwwwwwwwwwwww.

And add this to the printer settings, otherwise no background images and colors are printed.

            printSettings.SetPrintBGColorsAttribute(true);
            printSettings.SetPrintBGImagesAttribute(true);

John Hatton

unread,
Aug 10, 2013, 11:40:25 AM8/10/13
to wkhtmltop...@googlegroups.com

Hi Kees,

The way to submit improvements on GitHub is to fork and then make pull requests. You can use the Issues feature for bug reports. But the other wkthmltopdf list recipients would appreciate if we didn’t use this list.

thanks

jh

Yago Jesus

unread,
Aug 10, 2013, 12:37:36 PM8/10/13
to wkhtmltop...@googlegroups.com
It's interesting to follow the project, If you create a new mail-list,
please tell us !

2013/8/10 John Hatton <hatto...@gmail.com>:
> --
> ===================================================
> You received this message because you are subscribed to the "wkhtmltopdf
> General" group.
> To post to this group, send email to wkhtmltop...@googlegroups.com
> To unsubscribe from this group, send email to
> wkhtmltopdf-gen...@googlegroups.com
>
> For more options, visit this group at
> http://groups.google.com/group/wkhtmltopdf-general?hl=en?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "wkhtmltopdf General" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to wkhtmltopdf-gen...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages