Hallo,
das ist eine Weiterführung dieses Threads: CGContextRef kopieren?
Das ist der Code, der mir meine PDF zusammebaut:
Alles anzeigen
Der Code macht was er soll, allerdings ist der Speicherplatzaufwand bei ca. 250MB im Simulator. Wie kann ich das Problem beheben?
das ist eine Weiterführung dieses Threads: CGContextRef kopieren?
Das ist der Code, der mir meine PDF zusammebaut:
Quellcode
- NSString *filePath = /* file path to save PDFs to here */;
- UIGraphicsBeginPDFContextToFile(filePath, CGRectZero, nil);
- CGContextRef pdfContext = UIGraphicsGetCurrentContext();
- for (int i = 0; i < self.numberOfSmallFiles; i++)
- {
- @autoreleasepool
- {
- NSString *urlString = /* URL to PDF files on server */;
- NSURL *locationOfPDFOnServer = [[NSURL alloc] initWithString:urlString];
- NSData *pdfData = [[NSData alloc] initWithContentsOfURL:locationOfPDFOnServer];
- CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((__bridge CFDataRef)pdfData);
- CGPDFDocumentRef pdfDocument = CGPDFDocumentCreateWithProvider(dataProvider);
- size_t numberOfPages = CGPDFDocumentGetNumberOfPages(pdfDocument);
- for (size_t i = 1; i <= numberOfPages; i++)
- {
- @autoreleasepool
- {
- CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdfDocument, i);
- if (NULL == pdfPage)
- continue;
- CGRect pdfCropBox = CGPDFPageGetBoxRect(pdfPage, kCGPDFMediaBox);
- CGContextBeginPage(context, &pdfCropBox);
- CGContextDrawPDFPage(context, pdfPage);
- CGContextEndPage(context);
- }
- }
- CGPDFDocumentRelease(pdfDocument);
- CGDataProviderRelease(dataProvider);
- }
- }
- UIGraphicsEndPDFContext();
Der Code macht was er soll, allerdings ist der Speicherplatzaufwand bei ca. 250MB im Simulator. Wie kann ich das Problem beheben?