0
頁面
我從URL保存爲PDF文件,如果我保存單個網頁則是沒有問題的,但是當我保存整個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