• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting PDF data from a webView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting PDF data from a webView


  • Subject: Re: Getting PDF data from a webView
  • From: Jon Hull <email@hidden>
  • Date: Wed, 18 Jul 2007 18:51:50 -0700

This did the trick (from http://www.cocoadev.com/index.pl? GettingViewContentAsImage)... Big thanks to whoever created this method!!!!

- (NSImage *)createImageFromView:(NSView *)view {
NSRect rect = [view bounds];
NSBitmapImageRep *imageRep = [view bitmapImageRepForCachingDisplayInRect:rect];
[view cacheDisplayInRect:rect toBitmapImageRep:imageRep];
NSImage *image = [[[NSImage alloc] initWithSize:rect.size] autorelease];
[image addRepresentation:imageRep];

return image;
}



Thanks, Jon

On Jul 18, 2007, at 5:59 PM, Jon Hull wrote:

Hmm... It seems to be a bug in the webKit printing system. When I try to print to pdf from Safari, I get the same rendering issues.

Does anyone know of a way to get a bitmap representation of an entire view (even the part hidden by a scrollview) without using an offscreen window? If not, my current strategy is to have a second webview (*ick*) in an offscreen window which mirrors the first.

Thanks,
Jon


On Jul 18, 2007, at 9:48 AM, Jon Hull wrote:

I am trying to get a pdf image from a selection in a webView. At the moment I am just grabbing the whole view. It works fine, except the layout is wrong. It doesn't seem to be applying the CSS for some reason. Does anyone know what is going on? How can I get an image of a webView (including the stuff hidden by the scrollView)?

Here is the Code:

- (void)setPdfDoc:(PDFDocument*)newPdfDoc
{
[newPdfDoc retain];
[pdfDoc release];//does pdfView hold a copy of this (need to autorelease)???
pdfDoc = newPdfDoc;

[pdfView setDocument: pdfDoc];
}


- (IBAction)snap:(id)sender
{
NSData *viewImageData;

viewImageData=[[[[webView mainFrame]frameView]documentView] dataWithPDFInsideRect:[[[[webView mainFrame]frameView] documentView] bounds]];
[self setPdfDoc:[[[PDFDocument alloc] initWithData:viewImageData] autorelease]];

}


Oh, I had the same problem when just using the webView (instead of [[[webView mainFrame]frameView]documentView]) but it also grabbed the scrollbars.

Thanks,
Jon


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Getting PDF data from a webView (From: Jon Hull <email@hidden>)
 >Re: Getting PDF data from a webView (From: Jon Hull <email@hidden>)

  • Prev by Date: Re: Getting PDF data from a webView
  • Next by Date: KVC To-Many and BOOL
  • Previous by thread: Re: Getting PDF data from a webView
  • Next by thread: Re: Getting PDF data from a webView
  • Index(es):
    • Date
    • Thread