I want to move data between PDFKit's PDFDocument and Core Graphics's CGPDFContext, but I can't see how to do it. I'm using python, but any code that shows what methods and objects to use would be welcome.
Using CGPDFDocument would be easy, but there are reasons why I need to use PDFDocument instead. You'd think they'd be toll-free bridged.
Creating a context from PDFDocument.
pdfDoc = PDFDocument.alloc().initWithURL_(pdfURL) pdfData = pdfDoc.dataRepresentation() CGPDFContextCreate(pdfData, None, metaDict)
but I get: 'deflateEnd: error -3: (null).'
I can add a PDFPage to a CGPDFContext with drawWithBox ToContext, but that's only 10.12 and up. I tried this:
page = pdfDoc.pageAtIndex_(0) writeContext = CGPDFContextCreateWithURL(myURL, None, dictarray) CGContextBeginPage(writeContext, mbox) CGContextDrawPDFPage(writeContext, page.pageRef)
This gives me a segmentation fault. (Which is fixed by commenting out the drawPDF line, or replacing page
with a CGPDFPage
object, instead of a PDFPage
.
- Initialize a PDFDocument object with Data from the CGPDFContext.
I probably have to use CGDataProviders and Consumers somehow for this, but haven't a clue.