Speicherplatzproblem bei Erzeugung von PDF

  • Speicherplatzproblem bei Erzeugung von PDF

    Hallo,

    das ist eine Weiterführung dieses Threads: CGContextRef kopieren?

    Das ist der Code, der mir meine PDF zusammebaut:

    Quellcode

    1. NSString *filePath = /* file path to save PDFs to here */;
    2. UIGraphicsBeginPDFContextToFile(filePath, CGRectZero, nil);
    3. CGContextRef pdfContext = UIGraphicsGetCurrentContext();
    4. for (int i = 0; i < self.numberOfSmallFiles; i++)
    5. {
    6. @autoreleasepool
    7. {
    8. NSString *urlString = /* URL to PDF files on server */;
    9. NSURL *locationOfPDFOnServer = [[NSURL alloc] initWithString:urlString];
    10. NSData *pdfData = [[NSData alloc] initWithContentsOfURL:locationOfPDFOnServer];
    11. CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((__bridge CFDataRef)pdfData);
    12. CGPDFDocumentRef pdfDocument = CGPDFDocumentCreateWithProvider(dataProvider);
    13. size_t numberOfPages = CGPDFDocumentGetNumberOfPages(pdfDocument);
    14. for (size_t i = 1; i <= numberOfPages; i++)
    15. {
    16. @autoreleasepool
    17. {
    18. CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdfDocument, i);
    19. if (NULL == pdfPage)
    20. continue;
    21. CGRect pdfCropBox = CGPDFPageGetBoxRect(pdfPage, kCGPDFMediaBox);
    22. CGContextBeginPage(context, &pdfCropBox);
    23. CGContextDrawPDFPage(context, pdfPage);
    24. CGContextEndPage(context);
    25. }
    26. }
    27. CGPDFDocumentRelease(pdfDocument);
    28. CGDataProviderRelease(dataProvider);
    29. }
    30. }
    31. UIGraphicsEndPDFContext();
    Alles anzeigen

    Der Code macht was er soll, allerdings ist der Speicherplatzaufwand bei ca. 250MB im Simulator. Wie kann ich das Problem beheben?