Cannot create PDF document with 400+ pages on iOS

前端 未结 4 1377
生来不讨喜
生来不讨喜 2020-12-06 05:37

I am using the following pseudocode to generate a PDF document:

CGContextRef context = CGPDFContextCreateWithURL(url, &rect, NULL);

for (int i = 1; i &l         


        
4条回答
  •  余生分开走
    2020-12-06 05:39

    What about using a memory mapped file to back your CG data consumer? Then it doesn't necessarily have to fit in RAM all at once.

    I created an example here: https://gist.github.com/3748250

    Use it like this:

    NSURL * url = [ NSURL fileURLWithPath:@"pdf.pdf"] ;
    MemoryMappedDataConsumer * consumer = [ [ MemoryMappedDataConsumer alloc ] initWithURL:url ] ;
    
    CGDataConsumerRef cgDataConsumer = [ consumer CGDataConsumer ] ;
    
    CGContextRef c = CGPDFContextCreate( cgDataConsumer, NULL, NULL ) ;
    CGDataConsumerRelease( cgDataConsumer ) ;
    
    // write your PDF to context `c`
    
    CGPDFContextClose( c ) ;
    CGContextRelease( c ) ;
    
    return 0;
    

提交回复
热议问题