iphone - how to fit pdf page in entire view -


i read pdf files , displayed, code this:

- (void)drawlayer:(calayer *)layer incontext:(cgcontextref)ctx 

{

nslog(@"the layer  height %d, %d,%d ,%d",layer.bounds.size.width,layer.bounds.size.height,layer.bounds.origin.x,layer.bounds.origin.y);   int c=[currentpage intvalue]+1; nslog(@"drawing started");    if(uiinterfaceorientationisportrait([self interfaceorientation])){     layer.backgroundcolor=[uicolor blackcolor];     mypageref = cgpdfdocumentgetpage(mydocumentref, c);      nslog(@"draw layer");     cgsize pagesize = [kbdatasource pagesize];     gloginfo(@"the page ize getting in draw layer %@ ",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 %@", nsstringfromcgsize(aspectfitsize));     nslog(@"layer bounds are:%@  %@ ",nsstringfromcgsize(layer.bounds.size),nsstringfromcgpoint(layer.bounds.origin));     nslog(@"page size of book is:%@",nsstringfromcgsize(pagesize));     cgfloat aspectratio=pagesize.width/pagesize.height; /*       if (aspectratio>0.5 && aspectratio<=0.74) {         nslog(@"aspect ratio between 0.5 , 0.74");         cgcontexttranslatectm(ctx,-110 ,layer.bounds.size.height+100);         cgcontextscalectm(ctx, 1.28,-1.22);     }     else         if (aspectratio>0.74 && aspectratio<1) {             nslog(@"aspect ratio between 0.75 , 1");             //cgcontexttranslatectm(ctx, -145,layer.bounds.size.height+85);             //cgcontextscalectm(ctx, 1.4,-1.2);             cgcontexttranslatectm(ctx, -130,layer.bounds.size.height+75);             cgcontextscalectm(ctx, 1.35,-1.18);          }         else if(aspectratio>1) {             nslog(@"aspect ratio above 1");             cgcontexttranslatectm(ctx,-80,layer.bounds.size.height+80);             cgcontextscalectm(ctx, 1.2,-1.2);         }         else {             cgcontexttranslatectm(ctx, 0, layer.bounds.size.height);             cgcontextscalectm(ctx, 1.0, -1.0);         }*/   /*       cgfloat scalingratio;       if ((layer.bounds.size.width/pagesize.width)<((layer.bounds.size.height-41)/pagesize.height)){       scalingratio=layer.bounds.size.width/pagesize.width;      }     else {         scalingratio=(layer.bounds.size.height-41)/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 %@",nsstringfromcgrect(cropbox));     nslog(@"the crop box values %f",cropbox.origin.x);      nslog(@"the scaletoapply %f",scaletoapply);     nslog(@"the view bounds %@",[self.view description]);      if (scaletoapply == yscale)         cgcontextconcatctm(ctx, cgaffinetransformmaketranslation(-100, -150));     else         cgcontextconcatctm(ctx, cgaffinetransformmaketranslation(-180, -260)); //evans     cgcontextconcatctm(ctx, cgaffinetransformmakescale(scaletoapply, scaletoapply));     cgcontextconcatctm(ctx, cgpdfpagegetdrawingtransform(mypageref, kcgpdfcropbox, layer.bounds, 0, true));     //     //cgcontextconcatctm(ctx, cgaffinetransformmakescale(scaletoapply, scaletoapply));       cgcontextsetinterpolationquality(ctx, kcginterpolationhigh);      cgcontextsetrenderingintent(ctx, kcgrenderingintentdefault);     cgcontextdrawpdfpage(ctx, mypageref);     //cgcontextrestoregstate(ctx);      [loadingindicator stopanimating];     [loadingindicator1 stopanimating];     [loadingindicator2 stopanimating];  } 

it reads & displays pdf exactly, problem is,it not fit entire view each pdf,is there modification or correction need in code.please post suggestions , comments. thank you!!!

you need calculate scale values need page fit view. put proper values in your

cgcontextscalectm(ctx, 1.0, -1.0); 

call.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -