我想在PDFKit的PDFDocument和Core的CGPDFContext之间移动数据,但是我不知道怎么做。我正在使用python,但是任何显示要使用的方法和对象的代码都是受欢迎的。
使用CGPDFDocument很容易,但我需要使用PDFDocument是有原因的。你会觉得他们是免费搭桥的。
但我得到了:'deflateEnd: error -3:(Null)‘。
这给了我一个分割错误。(这是通过注释掉drawPDF行,或者用CGPDFPage对象代替CGPDFPage对象而不是PDFPage来修复的。
我可能不得不以某种方式使用CGDataProviders和消费者,但却毫无头绪。
发布于 2021-01-05 10:43:34
我已经把你的代码和我一直在做的一些PDF代码混在一起,并想出了把一个PDF页面绘制到CGContext中的方法。
我还使用了我的“参数”类,它只为我处理命令行选项。应该是不言而喻的。
我在几个不同的PDF上测试了这一点,并在一个新的PDF中得到了一个页面。
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <Quartz/Quartz.h>
#import "ArgumentsObj.h"
int main (int argc, char*const* argv)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
Arguments* aa = [Arguments argumentsWithCount:argc values:argv];
if ([aa countPositionalArguments] == 2) {
NSURL* furl = [NSURL fileURLWithPath:[aa positionalArgumentAt:0]];
PDFDocument* pdfd = [[PDFDocument alloc] initWithURL:furl];
PDFPage* pp = [pdfd pageAtIndex:0];
PDFRect mediabox = [pp boundsForBox:kPDFDisplayBoxMediaBox];
NSURL* nsfn = [NSURL fileURLWithPath:[aa positionalArgumentAt:1]];
NSDictionary* aux = [NSDictionary dictionaryWithObjectsAndKeys:@"main",kCGPDFContextCreator, nil];
CGContextRef cgpdf = CGPDFContextCreateWithURL((CFURLRef)nsfn,&mediabox,(CFDictionaryRef)aux);
CGPDFContextBeginPage(cgpdf, NULL);
CGContextDrawPDFPage(cgpdf, [pp pageRef]);
CGPDFContextEndPage(cgpdf);
CGPDFContextClose(cgpdf);
}
[pool release];
}https://stackoverflow.com/questions/49597379
复制相似问题