2012-07-31 3 views
0

필자는 화면에 PDF를 표시하려고하는 매우 이상하고 특별한 경우가 있습니다. 그러나 문제는 내 문서가 Acrobat Pro 프로그램에 표시되지 않고 흐린 선으로 표시된다는 것입니다.CGPDFDocumentRef가보기에 흐릿한 선을 표시하는 이유는 무엇입니까? (이미지 참조)

시계 이미지 :

http://imgur.com/ws4Qi

는 CGContext와 내가 고칠 수있는이 뭔가 (흐릿 선)인가 아니면 해상도 문제입니다. 내 코드는 다음과 같습니다.

- (id)initWithFrame:(CGRect)frame { 

self = [super initWithFrame:(CGRect)frame]; 
if (self) { 
    self.backgroundColor = [UIColor clearColor]; 
    NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"myPDF" ofType:@"pdf"]; 
    NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc]; 
    document = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfUrl); 
    currentPage = 1; 

} 

return self; 
} 

+ (void) renderPage: (CGPDFPageRef) page inContext: (CGContextRef) context{ 
[viewPDF renderPage:page inContext:context atPoint:CGPointMake(0, 0)]; 
} 

+ (void) renderPage: (CGPDFPageRef) page inContext: (CGContextRef) context atPoint:(CGPoint) point{ 
[viewPDF renderPage:page inContext:context atPoint:point withZoom:100]; 
} 

+ (void) renderPage: (CGPDFPageRef) page inContext: (CGContextRef) context atPoint: (CGPoint) point withZoom: (float) zoom{ 

CGRect cropBox = CGPDFPageGetBoxRect(page, kCGPDFCropBox); 
int rotate = CGPDFPageGetRotationAngle(page); 

CGContextSaveGState(context); 

// Setup the coordinate system. 
// Top left corner of the displayed page must be located at the point specified by the 'point' parameter. 
CGContextTranslateCTM(context, point.x, point.y); 

// Scale the page to desired zoom level. 
CGContextScaleCTM(context, zoom/100, zoom/100); 

// The coordinate system must be set to match the PDF coordinate system. 
switch (rotate) { 
    case 0: 
     CGContextTranslateCTM(context, 0, cropBox.size.height); 
     CGContextScaleCTM(context, 1, -1); 
     break; 
    case 90: 
     CGContextScaleCTM(context, 1, -1); 
     CGContextRotateCTM(context, -M_PI/2); 
     break; 
    case 180: 
    case -180: 
     CGContextScaleCTM(context, 1, -1); 
     CGContextTranslateCTM(context, cropBox.size.width, 0); 
     CGContextRotateCTM(context, M_PI); 
     break; 
    case 270: 
    case -90: 
     CGContextTranslateCTM(context, cropBox.size.height, cropBox.size.width); 
     CGContextRotateCTM(context, M_PI/2); 
     CGContextScaleCTM(context, -1, 1); 
     break; 
} 

// The CropBox defines the page visible area, clip everything outside it. 
CGRect clipRect = CGRectMake(0, 0, cropBox.size.width, cropBox.size.height); 
CGContextAddRect(context, clipRect); 
CGContextClip(context); 

CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0); 


CGContextSetLineJoin(context, kCGLineJoinRound); 

CGContextFillRect(context, clipRect); 

CGContextTranslateCTM(context, -cropBox.origin.x, -cropBox.origin.y); 

CGContextDrawPDFPage(context, page); 

CGContextRestoreGState(context); 


} 

+ (void) renderPage: (CGPDFPageRef) page inContext: (CGContextRef) context inRectangle: (CGRect) displayRectangle { 
if ((displayRectangle.size.width == 0) || (displayRectangle.size.height == 0)) { 
    return; 
} 

CGRect cropBox = CGPDFPageGetBoxRect(page, kCGPDFCropBox); 
int pageRotation = CGPDFPageGetRotationAngle(page); 

CGSize pageVisibleSize = CGSizeMake(cropBox.size.width, cropBox.size.height); 
if ((pageRotation == 90) || (pageRotation == 270) ||(pageRotation == -90)) { 
    pageVisibleSize = CGSizeMake(cropBox.size.height, cropBox.size.width); 
} 

float scaleX = displayRectangle.size.width/pageVisibleSize.width; 
float scaleY = displayRectangle.size.height/pageVisibleSize.height; 
float scale = scaleX < scaleY ? scaleX : scaleY; 

// Offset relative to top left corner of rectangle where the page will be displayed 
float offsetX = 0; 
float offsetY = 0; 

float rectangleAspectRatio = displayRectangle.size.width/displayRectangle.size.height; 
float pageAspectRatio = pageVisibleSize.width/pageVisibleSize.height; 

if (pageAspectRatio < rectangleAspectRatio) { 
    // The page is narrower than the rectangle, we place it at center on the horizontal 
    offsetX = (displayRectangle.size.width - pageVisibleSize.width * scale)/2; 
} 
else { 
    // The page is wider than the rectangle, we place it at center on the vertical 
    offsetY = (displayRectangle.size.height - pageVisibleSize.height * scale)/2; 
} 

CGPoint topLeftPage = CGPointMake(displayRectangle.origin.x + offsetX, displayRectangle.origin.y + offsetY); 

[viewPDF renderPage:page inContext:context atPoint:topLeftPage withZoom:scale * 100]; 
} 



-(void)drawRect:(CGRect)inRect{     
if(document) 

{ 
    CGContextRef ctx = UIGraphicsGetCurrentContext(); 
    CGPDFPageRef page = CGPDFDocumentGetPage(document, currentPage); 
    [viewPDF renderPage:page inContext:ctx atPoint:CGPointMake(10,10) withZoom:125]; 


} 

답변

0

확인. 문제는 PDF, Finale의 출처로 수정되었습니다. 2012 버전은 이제 PDF로 내보내기가 가능하도록 선을 내 보냅니다. 코드는 모든 화면에 PDF를 표시하려는 사용자를 돕기 위해 여기에 있습니다.