2012-07-18 64 views
1

我使用CoreText来生成一个包含一系列NSAttributedString的PDF文档,因此我创建了一个CTFrameSetterRef并为其提供了一个覆盖整个页面的框架,然后使用CTFrameDraw循环显示文本检查CTFrameGetVisibleStringRange的结果以检测何时开始新页面。这很好,但我怎么知道文本结束了?例如,文本可能会在最后一页停下来,我想在下面画一些图片。我怎样才能得到文本结束的位置?使用CoreText的多页PDF

CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)notesAttrString); 
do { 
    CTFrameRef frame = CTFramesetterCreateFrame(framesetter, currentRange, path, NULL); 
    if(frame) { 
     CTFrameDraw(frame, context); 

     if(currentRange.location < CFAttributedStringGetLength((CFAttributedStringRef)notesAttrString)) { 
      UIGraphicsBeginPDFPage(); 
     } else { 
      complete = YES; 
     } 
    } 
} while(!complete); 

(上面的代码是减少对过程的说明,而不是完整的)

回答

3

您可以使用CTFrameGetLineOrigins和检查的最后一行的起源,或者CTFramesetterSuggestFrameSizeWithConstraints得到整个帧的大小。