CLOSE SEARCH

[Snippet] Draw PDF document using Quartz

– (void)drawPDF:(CGContextRef)context
{

CFURLRef pdf = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR(“test.pdf”), NULL, NULL);
CGPDFDocumentRef doc = CGPDFDocumentCreateWithURL((CFURLRef)pdf);
CFRelease(pdf);

CGContextTranslateCTM(context, 0.0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);

CGPDFPageRef page = CGPDFDocumentGetPage(doc, 1);

CGContextSaveGState(context);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, self.bounds, 0, true);
CGContextConcatCTM(context, pdfTransform);

CGContextDrawPDFPage(context, page);
CGContextRestoreGState(context);

}

Filed under: iOS