
如何显示适合iPad显示边界或缩放状态的pdf?我尝试过使用不同的方法(方法2),但是它会产生一个问题,即pdf以90度的角度旋转.
方法1:
CGContextSaveGState(ctx);CGContextTranslateCTM(ctx,0.0,[self.vIEw bounds].size.height);CGContextScaleCTM(ctx,1.0,-1.0);CGContextConcatCTM(ctx,CGpdfpageGetDrawingtransform(page,kCGPdfcropBox,[self.vIEw bounds],true));CGContextDrawpdfpage(ctx,page); CGContextRestoreGState(ctx);
方法2:
CGpdfpageRef page = CGpdfdocumentGetPage(pdfdocument,PageNo+1);if(page){ CFRetain(page);}CGRect pageRect =CGpdfpageGetBoxRect(page,kCGpdfMediaBox);int angle= CGpdfpageGetRotationAngle(page);float pdfScale = self.bounds.size.wIDth/pageRect.size.wIDth;CGContextSetRGBFillcolor(context,1.0);CGContextFillRect(context,self.bounds);CGContextSaveGState(context);// Flip the context so that the pdf page is rendered// right sIDe up.CGContextTranslateCTM(context,self.bounds.size.height);CGContextScaleCTM(context,-1.0);// Scale the context so that the pdf page is rendered // at the correct size for the zoom level.CGContextScaleCTM(context,pdfScale,pdfScale); CGContextDrawpdfpage(context,page);CGContextRestoreGState(context); 任何人都可以向我推荐一个解决方案,允许任何大小和任何角度的pdf在两个方向上全屏显示在iPad上吗?如果您能为我提供代码片段或伪代码,那就太好了.
谢谢
这段代码是我自己的代码库的片段集合,所以不要只是将它复制粘贴到1个文件中,并期望它可以构建和运行.我发表了一些评论,以便您了解哪些属于哪里,并且您需要声明一些ivars才能正常工作.
// helper functionCGRect CGRectScaleAspectFit(CGRect sourceRect,CGRect fitRect){ if ( sourceRect.size.wIDth > fitRect.size.wIDth) { float scale = fitRect.size.wIDth / sourceRect.size.wIDth; sourceRect.size.wIDth = fitRect.size.wIDth; sourceRect.size.height = (int)(sourceRect.size.height * scale); } if ( sourceRect.size.height > fitRect.size.height) { float scale = fitRect.size.height / sourceRect.size.height; sourceRect.size.height = fitRect.size.height; sourceRect.size.wIDth = (int)(sourceRect.size.wIDth * scale); } return sourceRect;}// in your UIVIEw subclass init method CGpdfdocumentRef pdf = CGpdfdocumentCreateWithURL((CFURLRef)pdfURL); pdfpage = CGpdfdocumentGetPage(pdf,1); CGRect fitrect = CGRectMake(0,self.frame.size.wIDth,self.frame.size.height); CGRect pageRect = CGpdfpageGetBoxRect(pdfpage,kCGpdfMediaBox); CGRect f; f.origin.x=0; f.origin.y=0; f.size.height = self.frame.size.height; f.size.wIDth = self.frame.size.height * pageRect.size.wIDth/pageRect.size.height; f = CGRectScaleAspectFit(f,fitrect); // this is the actual pdf frame rectangle to fill the screen as much as possible pdfScale = f.size.height/pageRect.size.height;// in your UIVIEw subclass drawRect method CGContextSetRGBFillcolor(context,1.0); CGContextFillRect(context,self.bounds); CGContextSaveGState(context); CGContextTranslateCTM(context,self.bounds.size.height); CGContextScaleCTM(context,-1.0); CGContextScaleCTM(context,pdfScale); CGContextDrawpdfpage(context,pdfpage); CGContextRestoreGState(context); 总结 以上是内存溢出为你收集整理的如何在iPad上显示PDF全屏?全部内容,希望文章能够帮你解决如何在iPad上显示PDF全屏?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)