Multi page PDF with CoreText

I'm using CoreText to produce a PDF document which contains a series of NSAttributedString 's so I create a CTFrameSetterRef and give it a frame covering the whole page and then loop through using CTFrameDraw to draw the text checking the result of CTFrameGetVisibleStringRange to detect when to start a new page. This works great but how can I tell where the text ended? For example the text may stop halfway down the final page and I want to draw some images below. How can I get the position the text ended at?

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 );

(Above code is cut down for illustration of the process and not complete)


您可以使用CTFrameGetLineOrigins并检查最后一行的来源,或者使用CTFramesetterSuggestFrameSizeWithConstraints来获取整个框架的大小。

链接地址: http://www.djcxy.com/p/81986.html

上一篇: 如何获得一个适当的,任意宽的文本描边?

下一篇: CoreText多页PDF