привет, я пытаюсь напечатать pdf, он печатается хорошо, но проблема не в том, что ширина для каждого кода pdf.my такая:
//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];
}
Я пытаюсь подогнать всю ширину PDF, но она не работает. Я написал много вопросов по этому поводу и искал в сети, так что никто не может дать мне точную информацию о масштабировании.
спасибо всем.