【发布时间】:2011-06-05 18:44:56
【问题描述】:
大家好,我尝试了多种方法来根据 pdf 书的大小打印 pdf。我还搜索了许多链接和许多代码,例如苹果代码、github 和许多此类网站,但没有用。这个问题与许多问题和答案重复,但我仍然没有得到确切的结果。我的代码看起来像这样
-
(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
if(UIInterfaceOrientationIsPortrait([self interfaceOrientation])){ layer.backgroundColor=[UIColor blackColor]; myPageRef = CGPDFDocumentGetPage(myDocumentRef, c);CGSize pageSize = [kbDataSource pageSize]; GLogInfo(@"the page ize we are getting in draw layer is %@ ",NSStringFromCGSize(pageSize)); //CGContextSaveGState(ctx); CGSize aspectFitSize = [self getPageFitSizeOfSize:pageSize inSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height- __TOP_BRANDING_BAR_HEIGHT)]; CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0); CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx)); GLogDebug(@"aspect fitsize of image to %@", NSStringFromCGSize(aspectFitSize)); NSLog(@"layer bounds are:%@ %@ ",NSStringFromCGSize(layer.bounds.size),NSStringFromCGPoint(layer.bounds.origin)); NSLog(@"page size of the book is:%@",NSStringFromCGSize(pageSize)); CGFloat aspectRatio=pageSize.width/pageSize.height; CGRect cropBox = CGPDFPageGetBoxRect(myPageRef, kCGPDFCropBox); CGRect targetRect = layer.bounds; CGFloat xScale = targetRect.size.width / cropBox.size.width; CGFloat yScale = (targetRect.size.height-41) / cropBox.size.height; CGFloat scaleToApply = (xScale < yScale) ? xScale : yScale; CGContextTranslateCTM(ctx, 0.0, -41+layer.bounds.size.height); CGContextScaleCTM(ctx, 1.0, -1.0); NSLog(@"the crop box values are %@",NSStringFromCGRect(cropBox)); NSLog(@"the crop box values are %f",cropBox.origin.x); NSLog(@"the scaleToApply is %f",scaleToApply); NSLog(@"the view bounds are %@",[self.view description]); if (scaleToApply == yScale) CGContextConcatCTM(ctx, CGAffineTransformMakeTranslation(-100, -150)); else CGContextConcatCTM(ctx, CGAffineTransformMakeTranslation(-180, -260)); CGContextConcatCTM(ctx, CGAffineTransformMakeScale(scaleToApply, scaleToApply)); CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(myPageRef, kCGPDFCropBox, layer.bounds, 0, true)); CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh); CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault); CGContextDrawPDFPage(ctx, myPageRef);}
我粘贴了我在 drawlayer 中尝试过的所有代码。我给了很多随机数来适应整个屏幕的页面,最后我只得到了八本书(pdf)。
我的目标是打印任何覆盖整个 ipad 屏幕的 pdf。 我的结果只有少数 pdf。谁能告诉我它发生的确切原因,并告诉我将 pdf 打印到 ipad 整个屏幕的确切代码。
谢谢大家。
【问题讨论】:
标签: iphone objective-c ipad