如何在iOS7中绘制包含多条记录的PDF
我正在开发下面的PDF生成功能,该功能在iOS 6中运行良好,但在iOS 7中不起作用,因此请帮助我解决同样的问题如何在iOS7中绘制包含多条记录的PDF,ios,objective-c,pdf,ios7,quartz-core,Ios,Objective C,Pdf,Ios7,Quartz Core,我正在开发下面的PDF生成功能,该功能在iOS 6中运行良好,但在iOS 7中不起作用,因此请帮助我解决同样的问题 (float) drawText:(NSString *)body currentVehical:(NSInteger)currentVehical{ CGContextRef currentContext = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(currentContext,
(float) drawText:(NSString *)body currentVehical:(NSInteger)currentVehical{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(currentContext, 0.0, 0.0, 0.0, 1.0);
UIFont *font = [UIFont systemFontOfSize:14.0];
NSLog(@" FRame : \n%f\n%f",(self.pageSize.width - 2*kBorderInset-2*kMarginInset),
(self.pageSize.height-2*kBorderInset-2*kmarginiset))
提前感谢。我记得在为iOS7编译pdf渲染器时遇到了类似的问题,当时它在ios6.1中工作得非常好。我似乎记得字体大小是个问题,调试例程并检查字体大小和后续帧大小。很抱歉,我不能说得更具体了,因为3个月前就解决了,后来被遗忘了 希望此代码有助于:
+(void)drawTableDataAt:(Survey*)survey columns:(NSMutableArray*)savedColumns listContent:(NSArray*)surveyListContent withOrigin:(CGPoint)origin andRowCount:(int*)count andMaxRowOnPage:(int)size andLinesPerPage:(int)linesPerPage andColumnWidths:(NSMutableArray*)columnWidths withFont:(UIFont*)theFont withLabelFont:(UIFont*)theLabelFont
{
float rowHeight = theFont.lineHeight+3.0;
float padding = -5.0f;
// ………..
CGRect frame = CGRectMake(originX + padding, originY, [[columnWidths objectAtIndex:j] integerValue], rowHeight);
[self drawText:strValue inFrame:frame withFont:theFont withAlignment:kCTRightTextAlignment];
// ………..
}
+(void)drawText:(NSString*)textToDraw inFrame:(CGRect)frameRect withFont:(UIFont*)theFont withAlignment:(CTTextAlignment)textAlignment
{
CFStringRef stringRef = (__bridge_retained CFStringRef)textToDraw;
NSString *fontName = [theFont fontName];
CGFloat fontSize = [theFont pointSize];
// Set Font
CTFontRef font = CTFontCreateWithName( (__bridge CFStringRef)fontName, fontSize, NULL);
CTParagraphStyleSetting settings[ASD_ParagraphStylesSupported];
settings[0].spec = kCTParagraphStyleSpecifierAlignment;
settings[0].valueSize = sizeof(CTTextAlignment);
settings[0].value = &textAlignment;
CTParagraphStyleRef style = CTParagraphStyleCreate((const CTParagraphStyleSetting*) &settings, ASD_ParagraphStylesSupported);
// Create an attributed string
CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName, kCTParagraphStyleAttributeName };
CFTypeRef values[] = { font, [[UIColor blackColor] CGColor], style };
CFDictionaryRef attrs = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values,
sizeof(keys) / sizeof(keys[0]), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
// Prepare the text using a Core Text Framesetter with Attributes
CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, attrs);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
CGMutablePathRef framePath = CGPathCreateMutable();
CGPathAddRect(framePath, NULL, frameRect);
// Get the frame that will do the rendering.
CFRange currentRange = CFRangeMake(0, 0);
CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
CGPathRelease(framePath);
// 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);
// Core Text draws from the bottom-left corner up, so flip
// the current transform prior to drawing.
CGContextTranslateCTM(currentContext, 0, frameRect.origin.y*2);
CGContextScaleCTM(currentContext, 1.0, -1.0);
// Draw the frame.
CTFrameDraw(frameRef, currentContext);
CGContextScaleCTM(currentContext, 1.0, -1.0);
CGContextTranslateCTM(currentContext, 0, (-1)*frameRect.origin.y*2);
CFRelease(settings);
CFRelease(attrs);
CFRelease(style);
CFRelease(font);
CFRelease(frameRef);
CFRelease(stringRef);
CFRelease(framesetter);
}
我想简单的代码或解决方案,以绘制与文本的PDF。请建议,如果你有任何解决方案,我没有问题相关的iOS6。仅在iOS7中面临问题。感谢您对我的问题的宝贵反馈。
+(void)drawTableDataAt:(Survey*)survey columns:(NSMutableArray*)savedColumns listContent:(NSArray*)surveyListContent withOrigin:(CGPoint)origin andRowCount:(int*)count andMaxRowOnPage:(int)size andLinesPerPage:(int)linesPerPage andColumnWidths:(NSMutableArray*)columnWidths withFont:(UIFont*)theFont withLabelFont:(UIFont*)theLabelFont
{
float rowHeight = theFont.lineHeight+3.0;
float padding = -5.0f;
// ………..
CGRect frame = CGRectMake(originX + padding, originY, [[columnWidths objectAtIndex:j] integerValue], rowHeight);
[self drawText:strValue inFrame:frame withFont:theFont withAlignment:kCTRightTextAlignment];
// ………..
}
+(void)drawText:(NSString*)textToDraw inFrame:(CGRect)frameRect withFont:(UIFont*)theFont withAlignment:(CTTextAlignment)textAlignment
{
CFStringRef stringRef = (__bridge_retained CFStringRef)textToDraw;
NSString *fontName = [theFont fontName];
CGFloat fontSize = [theFont pointSize];
// Set Font
CTFontRef font = CTFontCreateWithName( (__bridge CFStringRef)fontName, fontSize, NULL);
CTParagraphStyleSetting settings[ASD_ParagraphStylesSupported];
settings[0].spec = kCTParagraphStyleSpecifierAlignment;
settings[0].valueSize = sizeof(CTTextAlignment);
settings[0].value = &textAlignment;
CTParagraphStyleRef style = CTParagraphStyleCreate((const CTParagraphStyleSetting*) &settings, ASD_ParagraphStylesSupported);
// Create an attributed string
CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName, kCTParagraphStyleAttributeName };
CFTypeRef values[] = { font, [[UIColor blackColor] CGColor], style };
CFDictionaryRef attrs = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values,
sizeof(keys) / sizeof(keys[0]), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
// Prepare the text using a Core Text Framesetter with Attributes
CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, attrs);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
CGMutablePathRef framePath = CGPathCreateMutable();
CGPathAddRect(framePath, NULL, frameRect);
// Get the frame that will do the rendering.
CFRange currentRange = CFRangeMake(0, 0);
CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
CGPathRelease(framePath);
// 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);
// Core Text draws from the bottom-left corner up, so flip
// the current transform prior to drawing.
CGContextTranslateCTM(currentContext, 0, frameRect.origin.y*2);
CGContextScaleCTM(currentContext, 1.0, -1.0);
// Draw the frame.
CTFrameDraw(frameRef, currentContext);
CGContextScaleCTM(currentContext, 1.0, -1.0);
CGContextTranslateCTM(currentContext, 0, (-1)*frameRect.origin.y*2);
CFRelease(settings);
CFRelease(attrs);
CFRelease(style);
CFRelease(font);
CFRelease(frameRef);
CFRelease(stringRef);
CFRelease(framesetter);
}