2

I've installed the library 'pyobjc-framework-Quartz'

pip install pyobjc-framework-Quartz

And in Python2, the following lines work perfectly:

provider = Quartz.CGDataProviderCreateWithFilename(input_file_path)
pdf = Quartz.CGPDFDocumentCreateWithProvider(provider)

But in Python3, I get the error message:

provider = Quartz.CGDataProviderCreateWithFilename(input_file_path)

ValueError: depythonifying 'char', got 'str' of 1

I've tried converting to char*

from ctypes import *
path = c_char_p(input_file_path)

but nothing seems to work. Can someone explain the error?

Thanks, Ryan

Ryan Loggerythm
  • 2,877
  • 3
  • 31
  • 39

1 Answers1

0

I've worked it out. The problem is that the string input_file_path in python3 is a Unicode string, and needs to be converted to a binary string before use in objc APIs.

input_file_path_converted = input_file_path.encode('utf-8')
provider = Quartz.CGDataProviderCreateWithFilename(input_file_path_converted)

.
(Except that it only work for filenames with standard "ASCII" range alphanumerics...)

benwiggy
  • 1,440
  • 17
  • 35