2 examples showing how to use dataWithPDFInsideRect method

2 examples showing how to use the instance method dataWithPDFInsideRect:
https://developer.apple.com/documentation/appkit/nsview/1483797-datawithpdfinsiderect?language=objc

The theView parameter is a NSView example NSTextView

UPDATE: createDataForPasteboard to use forType:“com.adobe.pdf”
So its possible to use New from Clipboard with Preview.app

on createDataForPasteboard(x, y, width, height, theView)
	set theSize to current application's NSMakeRect(x, y, width, height)
	set theData to theView's dataWithPDFInsideRect:theSize
	set pasteboard to current application's NSPasteboard's generalPasteboard()
	pasteboard's clearContents()
	pasteboard's setData:theData forType:"com.adobe.pdf"
end createDataForPasteboard

on createDataForImage(x, y, width, height, theView, thePath)
	set savePath to current application's |NSURL|'s fileURLWithPath:thePath
	set theSize to current application's NSMakeRect(x, y, width, height)
	set theData to theView's dataWithPDFInsideRect:theSize
	set theImage to current application's NSImage's alloc()'s initWithData:theData
	set tiffData to theImage's TIFFRepresentationUsingCompression:(current application's NSTIFFCompressionLZW) factor:0
	set imageRep to current application's NSBitmapImageRep's imageRepWithData:tiffData
	set imageData to imageRep's representationUsingType:(current application's NSBitmapImageFileTypeTIFF) |properties|:(missing value)
	imageData's writeToURL:savePath atomically:true
end createDataForImage