iPad上的PDF渲染问题

我有两个与在iPad / iPhone上处理PDF渲染相关的问题。

第一

在iPad上使用CGPDF函数呈现PDF页面时,我遇到了一些奇怪的问题。 奇怪的是,因为iPhone上的一切都很顺利,但在iPad上,我收到了很多与PDF相关的错误消息,即如下所示

invalid stream length 9785; endstream not found.
FlateDecode: decoding error: incorrect header check.
invalid function: failed to read 765 bytes.
stack underflow: popping past mark.
missing or invalid arguments for color operator.
FlateDecode: decoding error: incorrect header check.
FlateDecode: decoding error.
<Error>: FT_Open_Face failed: error 2.
<Error>: FT_Open_Face failed: error 85.
encountered unexpected object type: 7.
missing or invalid object number.
invalid image `ColorSpace' value.
unexpected symbol `obj' while reading object.
invalid descendant font for Type0 font.
font `F28' not found in document.
<Error>: FT_Outline_Decompose failed: error 20.
font `R222' not found in document.

......和其他许多人。 我知道这可能是一个错误的PDF结构的问题,但我不明白为什么我只能在iPad上看到所有这些错误,而在iPhone上,与iPad相比只有少数错误,并且在大多数情况下尽管页面显示正确的报告错误,这在iPad上也是如此。

iPhoneOS 3.2和3.1 / 4.0中的Quartz实现有什么区别吗? 是否有关于iPhone / iPad上可读的PDF格式的指导原则?

第二:

另一个问题是为不同的页面大小创建位图上下文。 我需要呈现相同的PDF页面以获取纵向和横向的方向。 但是,虽然它适用于肖像(在iPhone上),但它不适用于iPad上的风景,引发以下错误:

CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component colorspace; kCGImageAlphaPremultipliedLast; 4095 bytes/row.

用于创建上下文的代码如下所示:

/// Calculate memory block size needed
int bytesPerRow = (int)((int)_pageSize.width * 4);
int dataSize = (int)(bytesPerRow * _pageSize.height);

/// Allocate memory; As noted in docs, on iOS 4 it can be NULL, but as mentioned
/// below: Do not pass NULL if you are running on earlier operating systems.
/// So don't pass NULL...
void *bitmapData = malloc(dataSize);

if(!bitmapData) {
    /// Hm, out of memory?
    return NULL;
}

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGContextRef context = CGBitmapContextCreate(bitmapData, 
                                             _pageSize.width, 
                                             _pageSize.height, 
                                             8,             /* bits per component*/
                                             bytesPerRow,   /* bytes per row */
                                             colorSpace, 
                                             kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

CGColorSpaceRelease(colorSpace);

if(!context) {
    /// Something is really wrong!
    free(bitmapData);
    bitmapData = NULL;

    return NULL;
}

CGContextClipToRect(context, CGRectMake(0, 0, _pageSize.width, _pageSize.height));

    /// Ask data source to render contents
[_dataSource renderPageAtIndex: pageIndex inContext: context];

    /// Get bitmap image from context
CGImageRef image = CGBitmapContextCreateImage(context);

/// Free context AND previously allocated block of data
CGContextRelease(context);

free(bitmapData);
bitmapData = NULL;

    /// Finish operation...

正如我所说,它在iPhone下工作良好,适用于iPad上的纵向显示,而不适用于iPad上的横向显示。 唯一的区别是提供的当前页面大小。 但是,此处的页面大小不等于横向模式下的屏幕大小(1024x768),但其大小已计算为适合屏幕宽度,允许用户垂直滚动以查看完整页面。 通常,iPad上的页面大小为1024x1403(取决于PDF格式)。

我不明白为什么上面的代码不适合更大的页面大小。

有什么想法吗? 谢谢。


关于第二个问题,我只是有一个类似的问题。 事实上,警告表明当您使用4个字节像素时,每行分配4095个字节表示您在乘法之前可能无法正确转换为整数。

对我而言,我能够通过做相同的事情来解决它

int bytesPerRow = (int)((int)_pageSize.width * 4);

int bytesPerRow = lrintf(_pageSize.width) * 4;
链接地址: http://www.djcxy.com/p/95777.html

上一篇: PDF rendering issues on iPad

下一篇: managing images in an iphone/ipad universal app