首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PDF阅读器,白色细线

PDF阅读器,白色细线
EN

Stack Overflow用户
提问于 2012-09-14 13:14:03
回答 2查看 285关注 0票数 0

我的PDF阅读器显示细小的白线,如下所示

但是这个文件在acrobat阅读器上工作得很好,而且没有白线,下面是我处理pdf文件的方式。

代码语言:javascript
复制
CGRect contentRect = CGRectMake(0, 0, width, height);
CGContextRef context = CGBitmapContextCreate(NULL, 
                                             width, 
                                             height, 
                                             8,                     /* bits per component*/
                                             width * 4,     /* bytes per row */
                                             colorSpace, 
                                             kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

CGColorSpaceRelease(colorSpace);
CGContextSaveGState(context);
CGContextClipToRect(context, CGRectMake(0, 0, width, height));

// First fill the background with white.
CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
CGContextFillRect(context,contentRect);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);

CGContextDrawPDFPage(context,page);
CGImageRef image = CGBitmapContextCreateImage(context);
CGContextRestoreGState(context);
CGContextRelease(context);

我应该做什么来解决这个问题,更新我的代码或对我的PDF文件做一些事情?

EN

回答 2

Stack Overflow用户

发布于 2012-09-14 14:24:17

代码语言:javascript
复制
-(void)openPDfFile:(CGPDFDocumentRef)pdf

{

代码语言:javascript
复制
 // Get the PDF Page that we will be drawing     page = CGPDFDocumentGetPage(pdf, pageNumer);     CGPDFPageRetain(page);
代码语言:javascript
复制
// determine the size of the PDF page
CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFCropBox);
pdfScale = self.frame.size.height/pageRect.size.height;
pageRect.size = CGSizeMake(pageRect.size.width*pdfScale, pageRect.size.height*pdfScale);


// Create a low res image representation of the PDF page to display before the TiledPDFView
// renders its content.
UIGraphicsBeginImageContext(pageRect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

// First fill the background with white.
CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
CGContextFillRect(context,pageRect);

CGContextSaveGState(context);
// Flip the context so that the PDF page is rendered
// right side up.
CGContextTranslateCTM(context, 0.0, pageRect.size.height);
CGContextScaleCTM(context, 1.0, -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);

UIImage *backgroundImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];
backgroundImageView.frame = pageRect;
backgroundImageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:backgroundImageView];
[self sendSubviewToBack:backgroundImageView];

[self createPage:pageRect];

}

-(void)createPage:(CGRect)pageRect { //根据页面的大小创建TiledPDFView并将其缩放以适合视图。pdfView = [TiledPDFView alloc :pageRect andScale:pdfScale];pdfView setPage:page;

代码语言:javascript
复制
self.frame = pdfView.frame;

[self addSubview:pdfView];

}

尝试这些方法!!

票数 1
EN

Stack Overflow用户

发布于 2018-01-08 18:31:12

这对我的情况确实有帮助

代码语言:javascript
复制
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetShouldAntialias(context, NO); // solves the problem with white lines
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12418506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档