2011-01-18 5 views
0

Salut, je suis en train d'imprimer pdf, impression est bien, mais le problème est correspond pas à la largeur pour chaque code pdf.my est comme ça ..affichage PDF sur iPad

//for scalling 
-(CGSize)getPageFitSizeOfSize:(CGSize)sourceSize inSize:(CGSize)containerSize{ 
    // now fit the source to the container size - compute the width and height of the //image once it is aspect fit 
    // first fit it to the height 

    CGFloat heightWhenHeightIsFit = containerSize.height; 

    CGFloat widthWhenHeightIsFit = (sourceSize.width * heightWhenHeightIsFit)/sourceSize.height; 

    CGFloat heightWhenAspectFit = heightWhenHeightIsFit; 

    CGFloat widthWhenAspectFit = widthWhenHeightIsFit; 

    if(widthWhenAspectFit > containerSize.width){ 
     widthWhenAspectFit = containerSize.width; 
     heightWhenAspectFit = (sourceSize.height *widthWhenAspectFit)/sourceSize.width; 
    } 

    return CGSizeMake(widthWhenAspectFit, heightWhenAspectFit); 
} 


//printing 

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx 
{ 
    int c=[currentPage intValue]+1; 
    NSLog(@"drawing started"); 

    if(UIInterfaceOrientationIsPortrait([self interfaceOrientation])){ 
     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); 
     NSLog(@"the CGContextGetClipBoundingBox method rect %@",NSStringFromCGRect(CGContextGetClipBoundingBox(ctx))); 

    CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx)); 
    GLogDebug(@"aspect fitsize of image to %@", NSStringFromCGSize(aspectFitSize)); 
    GLogDebug(@"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; 
    NSLog(@"the value of aspect ratio is %f ",aspectRatio); 
    CGRect cropBox = CGPDFPageGetBoxRect(myPageRef, kCGPDFCropBox); 
    NSLog(@"the crop box values %@",NSStringFromCGRect(cropBox)); 
    CGRect targetRect = layer.bounds; 
    GLogDebug(@"the targetRect is %@",NSStringFromCGRect(targetRect)); 
    CGFloat xScale = targetRect.size.width/cropBox.size.width; 
    CGFloat yScale = (targetRect.size.height-41)/cropBox.size.height; 
    CGFloat scaleToApply = (xScale < yScale) ? xScale : yScale; 
    NSLog(@"the scaleToApply is %f,X-scale is %f,Y-scale is %f",scaleToApply,xScale,yScale); 

    CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height); 
    CGContextScaleCTM(ctx, 1.0, -1.0); 

    NSLog(@"the view bounds are %@",[self.view description]); 

    if (scaleToApply == yScale){ 
    NSLog(@"the values of CGAffineTransformMakeTranslation in if condition is %@ ",NSStringFromCGAffineTransform(CGAffineTransformMakeTranslation(-100, -150))); 
     CGContextConcatCTM(ctx, CGAffineTransformMakeTranslation(-100, -150)); 
    } 
    else{ 
     CGContextConcatCTM(ctx, CGAffineTransformMakeTranslation(-180, -260)); //evans 
     NSLog(@"the values of CGAffineTransformMakeTranslation in else condition is %@ ",NSStringFromCGAffineTransform(CGAffineTransformMakeTranslation(-180, -260))); 

    } 

    NSLog(@"the affineTransform makescale after applaying scaleToApplay %@",NSStringFromCGAffineTransform(CGAffineTransformMakeScale(scaleToApply, scaleToApply))); 
    CGContextConcatCTM(ctx, CGAffineTransformMakeScale(scaleToApply, scaleToApply)); 
     GLogDebug(@"the CGPDFPageGetDrawingTransform values are %@",NSStringFromCGAffineTransform(CGPDFPageGetDrawingTransform(myPageRef, kCGPDFCropBox, layer.bounds, 0, true))); 
    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]; 
} 

je suis en train de s'adapter toute la largeur de pdfs mais il ne fonctionne pas .. j'ai posté beaucoup de questions à ce sujet et ai cherché dans le filet aussi aucune utilisation peut-on s'il vous plaît donnez-moi l'échelle exacte. merci à tous.

+0

Veuillez ne pas laisser de commentaires demandant de l'aide pour votre question. [Ajoutez-y une prime si vous avez besoin d'aide] (http://stackoverflow.com/faq#bounty) (le système vous donnera 50 points supplémentaires pour la prime). – Will

Répondre

0

Il existe un moyen assez facile d'obtenir le rect d'une page PDF,

CGRect pdfPageRect = CGPDFPageGetBoxRect(CGPDFDocumentGetPage(myDocumentRef,pageNumber), kCGPDFMediaBox);

Trois choses vont affecter la taille du fichier PDF dessiné:

  • CGContextTranslateCTM (CTX, 0.0, hauteur); // HAUTEUR

  • CGContextConcatCTM (CTX, CGPDFPageGetDrawingTransform (p, kCGPDFCropBox, MY_RECT, 0, true)); // MY_RECT

  • CALayer.tileSize

L'échelle peut également être affectée par les deux chiffres de cette fonction: CGContextScaleCTM(ctx, 1, -1);