I inherited some iOS code that opens the source PDF file and creates CGContextRefon which we draw one page from the source document. The problem is that there are certain pages with one document, unfortunately, our reference document, which causes this code to crash.
The ultimate goal is to cache 8 pages at a time to improve user experience.
CFMutableDataRef consumerData = CFDataCreateMutable(kCFAllocatorDefault, 0);
CGDataConsumerRef contextConsumer = CGDataConsumerCreateWithCFData(consumerData);
CGPDFPageRef page = CGPDFDocumentGetPage(sourceDocument, pageNumber);
const CGRect mediaBox = CGPDFPageGetBoxRect(page, kCGPDFCropBox);
CGContextRef pdfOutContext = CGPDFContextCreate(contextConsumer, &mediaBox, NULL);
CGContextDrawPDFPage(pdfOutContext, page);
CGPDFPageRelease(page);
CGPDFContextEndPage(pdfOutContext);
CGPDFContextClose(pdfOutContext);
CGContextRelease(pdfOutContext);
(This is a simplified version of the code, the original opens the source document and page, checks the null value on pageand ctx, and then writes it ctxto a new document.)
There is no problem if instead of drawing in a PDF context, I draw a UIGraphics context created in this way:
CGContextRef graphicsContext = UIGraphicsGetCurrentContext();
, PDF.
, 99% 75% . PDF.
, . , CGPDF - ( , ).
: , / ?