Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS7中绘制包含多条记录的PDF_Ios_Objective C_Pdf_Ios7_Quartz Core - Fatal编程技术网

如何在iOS7中绘制包含多条记录的PDF

如何在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,

我正在开发下面的PDF生成功能,该功能在iOS 6中运行良好,但在iOS 7中不起作用,因此请帮助我解决同样的问题

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