RESOLVED INVALID 21933
dataWithPDFInsideRect: and CSS background broken
https://bugs.webkit.org/show_bug.cgi?id=21933
Summary dataWithPDFInsideRect: and CSS background broken
Mike Fischer
Reported 2008-10-28 14:07:23 PDT
Mac OS X 10.4.11 ppc, 10.5.5 i386, system WebKit as well as r37894 I'm trying to create a screenshot of a WebView using -[WebView dataWithPDFInsideRect:]. When used by itself the CSS media "print" will be used. So I tried the following: [Code snippet start] // webView is a valid WebView* which has loaded a web page (see below). // filePath is a valid path. For example: @"/Users/mike/Desktop/test.pdf". NSString *savedMediaStyle = [webView mediaStyle]; [webView setMediaStyle:@"screen"]; NSData *data = [webView dataWithPDFInsideRect:[webView bounds]]; [webView setMediaStyle:savedMediaStyle]; [data writeToFile:filePath atomically:YES]; [Code snippet end] The web page I used for testing had several style sheets, one of which was included with the attribute media="print". The result was not what I saw on screen. It seemed like some of the media "print" CSS was being applied. After consulting with Darin Adler on WebKitSDK-DEV I constructed a small test application. I used a minimal HTML file and one external stylesheet (media="print") for testing. The bug did not show! The same HTML file also worked fine in my large application. Then I added another stylesheet which used the background-color CSS property. This time the bug was reproducable. It also seems to reproduce with the background-image CSS property. In a third test I eliminated the first (media="print") stylesheet (keeping the second one with the background CSS property). Again the bug was reproducable. A fourth test showed that the bug also reproduces without any external stylesheets. A minimal HTML file for demonstarting the bug looks like this: [File: test.html] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>WebKit PDF Bug</title> <style type="text/css"> <!-- h1 { background-color: #dfd; } --> </style> </head> <body> <h1>Normal style</h1> </body> </html> [EOF] On screen the h1 element has a light green background. The PDF file written by the above code has a white background. PS. Is this related to: <https://bugs.webkit.org/show_bug.cgi?id=11992>?
Attachments
Mike Fischer
Comment 1 2008-10-28 17:24:53 PDT
Darin solved my problem by pointing me to the -[WebPreferences setShouldPrintBackgrounds:] method. Apparently backgrounds are not printed by default and generating a PDF is considerred printing. So this is not a bug. I have changed the status to INVALID accordingly.
Note You need to log in before you can comment on or make changes to this bug.