【发布时间】:2016-09-23 14:45:35
【问题描述】:
我正在从 url 保存一个 pdf 文件,如果我保存一个页面,那么没有问题,但是当我保存整个 pdf 应用程序时崩溃而没有任何日志
我的代码
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef)url);
NSString *pass = [_JSON objectForKey:@"pass"];
CGPDFDocumentUnlockWithPassword(document, [pass UTF8String]);
int i = (int) CGPDFDocumentGetNumberOfPages(document);
NSLog(@"Number Of pages: %d",i);
//Create the pdf context
for (int j = 0; j<i; j++) {
page = CGPDFDocumentGetPage(document, j+1); //Pages are numbered starting at 1
pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
mutableData = CFDataCreateMutable(NULL, j);
}
//NSLog(@"w:%2.2f, h:%2.2f",pageRect.size.width, pageRect.size.height);
CGDataConsumerRef dataConsumer = CGDataConsumerCreateWithCFData(mutableData);
CGContextRef pdfContext = CGPDFContextCreate(dataConsumer, &pageRect, NULL);
if (CGPDFDocumentGetNumberOfPages(document) > 0)
{
//Draw the page onto the new context
//page = CGPDFDocumentGetPage(document, 1); //Pages are numbered starting at 1
CGPDFContextBeginPage(pdfContext, NULL);
CGContextDrawPDFPage(pdfContext, page);
CGPDFContextEndPage(pdfContext);
}
else
{
NSLog(@"Failed to create the document");
}
CGContextRelease(pdfContext); //Release before writing data to disk.
//Write to disk
[(__bridge NSData *)mutableData writeToFile:@"/Users/user/Desktop/sample.pdf" atomically:YES];
//CleanUP
CGDataConsumerRelease(dataConsumer);
CGPDFDocumentRelease(document);
CFRelease(mutableData);
我认为问题出在循环上,但对这个模块了解不多,我是第一次尝试这个。 Here is the output log which i could never understand and there is no log in console
【问题讨论】:
标签: objective-c pdf