在PDFDocument和CGPDFContext之间移动数据?

2024-04-29 04:47:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在PDFKit的PDFDocument和Core Graphics的CGPDFContext之间移动数据,但我不知道如何做。我正在使用python,但是任何显示要使用的方法和对象的代码都是受欢迎的。
使用CGPDFDocument会很容易,但是有理由我需要使用PDFDocument来代替。你会认为他们会免费搭桥。你知道吗

  1. 从PDFDocument创建上下文。你知道吗

    pdfDoc = PDFDocument.alloc().initWithURL_(pdfURL)
    pdfData = pdfDoc.dataRepresentation()
    CGPDFContextCreate(pdfData, None, metaDict)
    

但我得到:'泄气:错误-3:(空)。'

  1. 我可以将PDFPage添加到CGPDFContext,并使用drawWithBox添加到Context,但这仅为10.12及更高版本。我试过这个:

    page = pdfDoc.pageAtIndex_(0)
    writeContext = CGPDFContextCreateWithURL(myURL, None, dictarray)
    CGContextBeginPage(writeContext, mbox)
    CGContextDrawPDFPage(writeContext, page.pageRef)
    

这给了我一个分割错误。(这是通过注释掉drawPDF行,或者用CGPDFPage对象代替PDFPage来修复的。你知道吗

  1. 使用CGPDFContext中的数据初始化PDFDocument对象。你知道吗

为此,我可能不得不使用CGDataProviders和consumer,但我对此一无所知。你知道吗


Tags: 数据对象方法corenone错误pagepdfkit