2012-03-31 52 views
-1

我使用下面的代码来绘制和旋转PDF文件。它与iOS 5.x完美无瑕,但在iOS 4.3下,只有一个白页出现在调试器中的错误:iOS 4.3 PDF文件呈现问题

无效`Contents':不是一个数组流。

错误发生在“CGContextDrawPDFPage(context,pdfPage)”之后;

为什么它可以与iOS 5.x一起使用,但不是4.3.x?我尝试了不同的PDF文件,但仍得到相同的结果。

我该如何解决这个问题?

pdfpage定义为:

- (void)setPage:(CGPDFPageRef)newPage 
{ 
    CGPDFPageRelease(self->pdfPage); 
    self->pdfPage = CGPDFPageRetain(newPage); 
} 

在那里发生的方法,包括:

-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context 
{ 
    // First fill the background with white. 
    CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0); 
    CGContextFillRect(context,self.bounds); 
    CGContextSaveGState(context); 
    int rotate = CGPDFPageGetRotationAngle(pdfPage); 

    switch (rotate) { 
     case 0: 
      CGContextTranslateCTM(context, 0.0, self.bounds.size.height); 
      CGContextScaleCTM(context, 1, -1); 
      break; 
     case 90: 
      CGContextScaleCTM(context, 1.0, -1.0); 
      CGContextRotateCTM(context, -M_PI/2); 
      break; 
     case 180: 
     case -180: 
      CGContextScaleCTM(context, 1, -1); 
      CGContextTranslateCTM(context, self.bounds.size.width, 0); 
      CGContextRotateCTM(context, M_PI); 
      break; 
     case 270: 
     case -90: 
      CGContextTranslateCTM(context, self.bounds.size.height, self.bounds.size.width); 
      CGContextRotateCTM(context, M_PI/2); 
      CGContextScaleCTM(context, -1, 1); 
      break; 
    } 

    CGContextSetInterpolationQuality(context, kCGInterpolationHigh); 
    CGContextSetRenderingIntent(context, kCGRenderingIntentDefault); 
    CGContextScaleCTM(context, myScale,myScale); 
    CGContextDrawPDFPage(context, pdfPage); // the error shows up right after executing this line 
    CGContextRestoreGState(context); 
} 
+1

什么是'pdfPage'?检查它是否正确初始化。 – 2012-03-31 07:35:03

+0

请注意,向下/向上投票不帮助我解决问题! – 2012-03-31 07:36:21

+0

@MitulNakum其初始化正确它与ios 5.x但不是ios 4.3.x我有更新代码。感谢您试图提供帮助。 – 2012-03-31 07:39:04

回答

0

据PDF说明书中,页字典的/目录条目可以是流对象或流对象数组。根据错误消息,似乎iOS 4.3没有正确实现PDF规范,它总是期望/ Contents项的一组数据流,并且您的文件使用单个流对象。 iOS 5可能解决了这个问题。

+0

我回到了苹果pdf渲染的例子,现在它也适用于ios 4.3。但我没有得到它是什么问题。无论如何,如果有人遇到这个问题,就拿着苹果的例子 – 2012-04-03 19:45:06

+1

花几个小时试图找出两个样本(ZoomingPDFViewer)之间有什么区别,我终于找到了它。在iOS 5之前,您需要保留对PDFDocument的引用并将其发布到dealloc中。在iOS 5之后,您可以在将CGPDFPageRef传递给TiledView后立即释放。为什么?不知道。 – ipodishima 2012-07-31 14:16:30

0

首先尝试做CGPDFDocumentRetain(yourCGPDFDocumentRef)