• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.9.5/pyobjc-42/2.5/pyobjc/pyobjc-framework-Quartz/Examples/Programming with Quartz/BasicDrawing/
1from Cocoa import *
2from Quartz import *
3
4import AppDrawing
5
6def myCreatePDFDataFromPasteBoard():
7    # Obtain the pasteboard to examine.
8    pboard = NSPasteboard.generalPasteboard()
9
10    # Scan the types of data on the pasteboard and return the first type available that is
11    # listed in the array supplied. Here the array of requested types contains only one type,
12    # that of PDF data. If your application could handle more types, you would list them in
13    # the creation of this array.
14    type = pboard.availableTypeFromArray_([NSPDFPboardType])
15
16    # If the string is non-nil, there was data of one of our requested types
17	# on the pasteboard that can be obtained.
18    if type is not None:
19        # Test that the type is the PDF data type. This code is not strictly necessary
20        # for this example since we only said we could handle PDF data, but is appropriate
21        # if you can handle more types than just PDF.
22        if type == NSPDFPboardType:
23            # Get the PDF data from the pasteboard.
24            pdfData = pboard.dataForType_(type)
25            if pdfData is not None:
26                return pdfData
27            else:
28                NSLog("Couldn't get PDF data from pasteboard!")
29    else:
30        NSLog("Pasteboard doesn't contain PDF data!")
31    return None
32
33def addPDFDataToPasteBoard(command):
34    pdfData = cfDataCreatePDFDocumentFromCommand(command)
35    if pdfData is not None:
36        pboard = NSPasteboard.generalPasteboard()
37        pboard.declareTypes_owner_(NSPDFPboardType, None)
38        pboard.setData_forType_(pdfData, NSPDFPboardType)
39