0

私のPDFリーダーには、このような細い白い線が表示されますここに画像の説明を入力

しかし、このファイルは acrobat リーダーで問題なく動作し、白い線はありません。これが私の 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 ファイルに何かを行う必要がありますか?

4

2 に答える 2

1
-(void)openPDfFile:(CGPDFDocumentRef)pdf

{
// 描画する PDF ページを取得 page = CGPDFDocumentGetPage(pdf, pageNumer); CGPDFPageRetain(ページ);

// 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 { // PDF ページのサイズに基づいて TiledPDFView を作成し、ビューに合わせてスケーリングします。pdfView = [[TiledPDFView alloc] initWithFrame:pageRect andScale:pdfScale]; [pdfView setPage:ページ];

self.frame = pdfView.frame;

[self addSubview:pdfView];

}

これらの方法を試してください!!

于 2012-09-14T06:24:17.380 に答える
1

これは私の場合に役立ちました

CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetShouldAntialias(context, NO); // solves the problem with white lines
于 2018-01-08T10:31:11.803 に答える