1
votes

I am new to ipad application development. I am rendering a pdf book using CGPDFDocumentRef in the iPad. I am able to render the pdf properly which is coming in the centre of the page. Its leaving small length of white space on all the sides. I am trying to scale that image which we are getting in centre to fit the page exactly...can any one help me out how to make that fit into the ipad screen size?

myPageRef = CGPDFDocumentGetPage(myDocumentRef, pageNo);
CGContextTranslateCTM(ctx,0 , layer.bounds.size.height);
CGContextScaleCTM(ctx, 1.0,-1.0);
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(myPageRef,kCGPDFCropBox , layer.bounds, 0, true));
CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh); 
CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
CGContextDrawPDFPage(ctx, myPageRef);

By using this code, I am getting the pdf document in center, now please help me out how to fit it to the page????

Thank you,
Raju

1

1 Answers

0
votes

You need the CGPDFPageGetDrawingTransform function to get a affine transform that will do exactly that.

pdfToPageTransform = CGPDFPageGetDrawingTransform(myPageRef, kCGPDFMediaBox, layer.bounds, 0, true);
CGContextConcatCTM(ctx, pdfToPageTransform);
CGContextDrawPDFPage(ctx, myPageRef)

The third parameter is a CGRect that defines the square you want you PDF to fit in. The last parameter says if you accept deformation to fit the CGRect or not.