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);
(上面的代码是减少对过程的说明,而不是完整的)