在整个屏幕上呈现pdf的问题pdf
大家好我尝试了很多方式来打印PDF与PDF书的大小。我也搜索了许多链接和许多代码,如苹果代码,github和许多这样的类型的网站,但没有用。这个问题是重复的许多问题和答案,但我仍然没有得到确切的result.my代码看起来像这样在整个屏幕上呈现pdf的问题pdf
-
(无效)drawLayer:(CALayer的*)层inContext的:(CGContextRef)CTX { (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);
}
我粘贴所有i的drawlayer试过的代码。我给了很多随机数字,以适应整个页面的页面,最后我只获得了八本书(pdf)。
我的目标是打印任何PDF与整个ipad屏幕覆盖。 我的结果是只有几个pdfs.cf任何人告诉我为什么发生的确切原因,并告诉我确切的代码打印PDF到整个ipad屏幕。
谢谢大家。
PDF文件中的页面没有标准大小。而且,由于您正在计算比例以保持正确的宽高比,因此并非所有的PDF文件都会占用整个屏幕。
基于上面的代码,就可以使所有的PDF文件适合整个屏幕通过改变
CGContextConcatCTM(ctx, CGAffineTransformMakeScale(scaleToApply, scaleToApply));
到
CGContextConcatCTM(ctx, CGAffineTransformMakeScale(xScale, yScale));
这将搞砸了长宽比,虽然。
为什么不直接使用UIDocumentInteractionController来显示PDF?试图按照您的方式呈现PDF会容易得多?我已经使用UIDocumentInteractionController几个实例来预览PDF,Word文档,PPT课件等
检查出来HERE.
这可能给你所需要的(装满PDF全屏幕)。它也将允许您打印文档,并在需要时打开另一个应用程序...
有一种简单的方法来阅读iPhone/iPad中的PDF:1.取一个UIwebView(名称:pdfView)。告诉上司IBOutlet中连接到它&委托给FilesOwner 3.In viewDidLoad中
[self.pdfView的loadRequest:的NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[一个NSBundle mainBundle] pathForResource:@ “ObjC” ofType:@“PDF “]]]];
4.ObjC.pdf应该在资源文件夹中。现在,将不同大小的pdf页面放入iPad的屏幕中,只需打开相应的.xib文件,然后转到UIwebView的检查器,然后查看Web视图属性,标记缩放页面以适合选项。
嗨Altealice,我尝试了上面提到的内容,但是它对我的解决方案没有任何帮助。我发布了我的新代码。 – user568065 2011-01-10 06:58:26
当您使用我建议的代码时会发生什么? – Altealice 2011-01-10 08:12:18