2012-09-14 147 views
0

我的PDF閱讀器顯示細白線這樣enter image description herePDF閱讀器,細白線

但該文件適用於Acrobat Reader和無白線細,​​這是我如何處理我的PDF文件

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文件做些什麼?

回答

1
-(void)openPDfFile:(CGPDFDocumentRef)pdf 

{
//獲取PDF頁面,我們將繪製 頁= CGPDFDocumentGetPage(PDF,pageNumer); CGPDFPageRetain(page);

// 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]; 

}

- (空)createPage:(的CGRect)pageRect {// 創建基於PDF頁面的大小TiledPDFView和規模,以適應視圖。 pdfView = [[TiledPDFView alloc] initWithFrame:pageRect andScale:pdfScale]; [pdfView setPage:page];

self.frame = pdfView.frame; 

[self addSubview:pdfView]; 

}

嘗試這些方法!

1

這確實幫助我的情況

CGContextSetInterpolationQuality(context, kCGInterpolationHigh); 
CGContextSetShouldAntialias(context, NO); // solves the problem with white lines