I want to write a command line tool to render HTML in PDF file...

using WebKit and dataWithPDFInsideRect but it doesn't work: the page is empty, what am I doing wrong ?
When using AppKit functionalities in a command tool, you should instantiate NSApplication by calling [NSApplication sharedApplication].
If you need to do some rendering in NSView, you also need to create an off-screen window.
At this point you should be able to render any kind of NSView or to manipulate NSImage.
However rendering of WebView has some more requirement: it's asynchronous, so you also need to invoke the NSRunLoop mechanism to wait for the asynchronous rendering task to finish.
Here a small snippet to be used as an starting point example, (add error checking for real world usage):

#import
#import

@interface WebRenderer : NSObject
{
WebView *_view ;
NSString *_html ;
BOOL _loaded ;
}

+ (id)newWebRenderInView:(WebView *)inView forHTMLString:(NSString *)inHTMLString;
- (id)initWebRenderInView:(WebView *)inView forHTMLString:(NSString *)inHTMLString;
- (BOOL)isLoaded;
- (void)renderHTML;
- (void)renderPDFToFile:(NSString *)inPath;

@end

@implementation WebRenderer

+ (id)newWebRenderInView:(WebView *)inView forHTMLString:(NSString *)inHTMLString
{
return [[[WebRenderer alloc] initWebRenderInView:inView forHTMLString:inHTMLString] autorelease] ;
}

- (id)initWebRenderInView:(WebView *)inView forHTMLString:(NSString *)inHTMLString
{
if (self = [self init]) {
_view = inView ;
_html = [inHTMLString retain] ;
_loaded = NO ;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(webPageFinishedLoading:) name:WebViewProgressFinishedNotification object:nil];
}
return self ;
}

- (void)dealloc
{
[_html release] ;
[super dealloc] ;
}

- (void)renderHTML
{
[[_view mainFrame] loadHTMLString:_html baseURL:nil] ;
}

- (void)renderPDFToFile:(NSString *)inPath
{
[[_view dataWithPDFInsideRect:[_view frame]] writeToFile:inPath atomically:YES] ;
}

- (void)webPageFinishedLoading:(NSNotification *)inNotification
{
_loaded = YES ;
}

- (BOOL)isLoaded
{
return _loaded ;
}

@end

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSRect r = NSMakeRect(0, 0, 640, 480);

[NSApplication sharedApplication];

NSWindow *win = [[NSWindow alloc] initWithContentRect:NSMakeRect(-1024.0, -1024.0, 1024.0, 1024.0) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES] ;
[win makeKeyWindow] ;

WebView * view = [[WebView alloc] initWithFrame: r];

WebRenderer *aRenderer = [WebRenderer newWebRenderInView:view forHTMLString:@"Hello world!"] ;
[aRenderer renderHTML] ;

while (![aRenderer isLoaded]) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSCalendarDate distantPast]];
}
[aRenderer renderPDFToFile:@"/tmp/tmp.pdf"] ;

[pool release];
return 0;
}