我想创建多页PDF,我想在PDF上绘制多个矩形。
我尝试使用drawInRect:withAttributes方法绘制每个字符串,我能够以PDF格式绘制我的内容但是如果我们有长字符串就有一个问题,那么我们无法在不获取字符串范围的情况下管理它。我认为使用Render Method使用Core Text Framework是可行的。
然后我尝试使用CoreText绘制内容,但我无法管理多个Rect。
例如,如果我有First Rect那么无论是否长,它都正确地翻转。它正在发挥作用。
但对于其他作品,我无法管理其逻辑。请帮帮我。
我正在使用以下方法渲染文字
// Use Core Text to draw the text in a frame on the page.
- (CFRange) renderTextWithRange:(CFRange)currentRange andFramesetter:(CTFramesetterRef)framesetter andFrameRect:(CGRect) frameRect2
{
// Get the graphics context.
CGContextRef currentContext = UIGraphicsGetCurrentContext();
// Put the text matrix into a known state. This ensures
// that no old scaling factors are left in place.
CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);
CGFloat height = 648;
if (frameRect2.size.height <= 648)
{
height = frameRect2.size.height;
}
// Create a path object to enclose the text. Use 72 point
// margins all around the text.
CGRect frameRect = CGRectMake(frameRect2.origin.x, frameRect2.origin.y, 468 - frameRect2.origin.x, height);
CGMutablePathRef framePath = CGPathCreateMutable();
CGPathAddRect(framePath, NULL, frameRect);
// Get the frame that will do the rendering.
// The currentRange variable specifies only the starting point. The framesetter
// lays out as much text as will fit into the frame.
CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
CGPathRelease(framePath);
CGFloat reverseTrans = frameRect.origin.y*2;
NSLog(@"Reverse : %f", reverseTrans);
// Core Text draws from the bottom-left corner up, so flip
// the current transform prior to drawing.
CGContextTranslateCTM(currentContext, 0, reverseTrans);
CGContextScaleCTM(currentContext, 1.0, -1.0);
// Draw the frame.
CTFrameDraw(frameRef, currentContext);
CGFloat reverseTrans2 = (-1)*frameRect.origin.y*2;
NSLog(@"Reverse2 : %f", reverseTrans2);
CGContextScaleCTM(currentContext, 1.0, -1.0);
CGContextTranslateCTM(currentContext, 0, reverseTrans2);
// Update the current range based on what was drawn.
currentRange = CTFrameGetVisibleStringRange(frameRef);
currentRange.location += currentRange.length;
currentRange.length = 0;
CFRelease(frameRef);
return currentRange;
}
请尝试以这种方式帮助我,我可以通过我的矩形,它将在PDF上绘制适当的可管理内容。
目前我无法管理镜像转换。
请建议......
提前致谢!