在pdf的整个屏幕上渲染pdf的问题 [英] problem with rendering pdf on the entire screen of pdf

查看:123
本文介绍了在pdf的整个屏幕上渲染pdf的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我在很多方面尝试根据pdf book的大小打印pdf.i还搜索了许多链接和许多代码,如苹果代码,github和许多此类网站但没有用。这个问题是许多问题和答案的重复,但我仍然没有得到确切的结果。我的代码看起来像这样

Hi all I tried in many ways to print a pdf according with the size of the pdf book.i also searched in many links and many codes like apple codes,github and many such type of sites but no use. This question is duplicate of many questions and answers but still i didN't get exact result.my code is looking like this


  • (void)drawLayer:(CALayer *)图层inContext:(CGContextRef)ctx
    {

    if(UIInterfaceOrientationIsPortrait([self interfaceOrientation])){
    layer.backgroundColor = [UIColor blackColor ]。
    myPageRef = CGPDFDocumentGetPage(myDocumentRef,c);

  • (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
    if(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);

}

我粘贴了我在drawlayer中尝试的所有代码。我提供了许多随机数字以适应整个页面的页面,最后我只获得了八本书(pdf)。

I pasted all the code which i tried in drawlayer. I gave many random numbers to fit the page entire screen finally i got only for Eight books(pdfs).

我的目标是打印任何带有整个ipad屏幕的pdf 。
我的结果只有几个pdfs.can任何人告诉我它发生的确切原因,并告诉我将PDF格式打印到ipad的整个屏幕的确切代码。

My goal is to print any pdf with the entire ipad screen covering. my result is getting only for few pdfs.can any one tell me the exact reason why it is happening and also tell me exact code to print the pdf to the entire screen of ipad.

谢谢大家。

推荐答案

PDF文件中的页面没有标准尺寸。由于您正在计算比例以保持正确的宽高比,因此并非所有PDF文件都占据整个屏幕。

Pages in PDF files don't have a standard size. And since you are computing the scale to retain the correct aspect ratio, not all of your PDF files will take up the entire screen.

根据您的上述代码,您可以通过更改

Based on your code above, you can make all PDF files fit the entire screen by changing

CGContextConcatCTM(ctx, CGAffineTransformMakeScale(scaleToApply, scaleToApply));

CGContextConcatCTM(ctx, CGAffineTransformMakeScale(xScale, yScale));

但这会搞砸纵横比。

这篇关于在pdf的整个屏幕上渲染pdf的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆