2
A
回答
2
編輯:
假設你的plist的結構爲: 。
================ 在非常首先你應該添加框架coreText和石英纖芯他們進口和定義一些宏是這樣的:
#import <QuartzCore/QuartzCore.h>
#import <CoreText/CoreText.h>
#define LEFT_MARGIN 25
#define RIGHT_MARGIN 25
#define TOP_MARGIN 35
#define BOTTOM_MARGIN 50
#define BOTTOM_FOOTER_MARGIN 32
#define DOC_WIDTH 1004
#define DOC_HEIGHT 768
,你可以得到這樣的plist數據:
NSString *path = [[NSBundle mainBundle] pathForResource:@"recipes" ofType:@"plist"];
// Load the file content and read the data into arrays
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
// 編輯
tableData = [dict objectForKey:@"RecipeName"];//tabledata is global array
self.textToDraw = [tableData objectAtIndex:0];
// 編輯
但低於下面的代碼,你可以創建動態pdf:
-(void) btnDrawPdf
{
// pageSize = CGSizeMake(612, 792);
NSString *fileName = @"DemoNetwrk.pdf";
NSString *fontName = @"Helvetica";
// NSString * textToDraw = @「你的數據來自plist」;評論這個現在
//[self generatePdfWithFilePath:pdfFileName];
[self createPDF:fileName **withContent:self.textToDraw** forSize:14 forFontName:fontName andColor:[UIColor blackColor]];
}
//多頁PDF和PDF將保存在doc目錄庫>應用程序支持> iPhoneSimulator>庫>文檔(在完美的iOS 4.3)
- (void) createPDF:(NSString *)fileName withContent:(NSString *)content forSize:(int)fontSize forFontName:(NSString *)fontName andColor:(UIColor *)color
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *newFilePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];
CGRect a4Page = CGRectMake(0, 0, DOC_WIDTH, DOC_HEIGHT);
NSDictionary *fileMetaData = [[NSDictionary alloc] init];
if (!UIGraphicsBeginPDFContextToFile(newFilePath, a4Page, fileMetaData)) {
NSLog(@"error creating PDF context");
return;
}
BOOL done = NO;
CGContextRef context = UIGraphicsGetCurrentContext();
CFRange currentRange = CFRangeMake(0, 0);
CGContextSetTextDrawingMode (context, kCGTextFill);
CGContextSelectFont (context, [fontName cStringUsingEncoding:NSUTF8StringEncoding], fontSize, kCGEncodingMacRoman);
CGContextSetFillColorWithColor(context, [color CGColor]);
// Initialize an attributed string.
CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
CFAttributedStringReplaceString (attrString, currentRange, (CFStringRef)content);
// Create the framesetter with the attributed string.
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString);
do {
UIGraphicsBeginPDFPage();
CGMutablePathRef path = CGPathCreateMutable();
CGRect bounds = CGRectMake(LEFT_MARGIN,
TOP_MARGIN,
DOC_WIDTH - RIGHT_MARGIN - LEFT_MARGIN,
DOC_HEIGHT - TOP_MARGIN - BOTTOM_MARGIN);
CGPathAddRect(path, NULL, bounds);
// Create the frame and draw it into the graphics context
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, currentRange, path, NULL);
if(frame) {
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0, bounds.origin.y);
CGContextScaleCTM(context, 1, -1);
CGContextTranslateCTM(context, 0, -(bounds.origin.y + bounds.size.height));
CTFrameDraw(frame, context);
CGContextRestoreGState(context);
// Update the current range based on what was drawn.
currentRange = CTFrameGetVisibleStringRange(frame);
currentRange.location += currentRange.length;
currentRange.length = 0;
CFRelease(frame);
}
// If we're at the end of the text, exit the loop.
if (currentRange.location == CFAttributedStringGetLength((CFAttributedStringRef)attrString))
done = YES;
}
while(!done);
UIGraphicsEndPDFContext();
// [fileMetaData release];
CFRelease(attrString);
CFRelease(framesetter);
}
最後我是得到這個:
它會幫助你...
0
This可能是你在找什麼。
將其轉換爲PDF(加載數據,並在UIView
或UIView
繼承的類顯示它之前,您應該使您的plist屏幕
相關問題
- 1. 從plist生成隨機名
- 2. 從plist文件生成tableview
- 3. IOS - 從iphone中的UIwebview生成PDF
- 4. iOS - 從多個文件生成pdf
- 5. ios - 生成從CoreData填充的PDF
- 6. 從ODT生成PDF
- 7. 從latex生成PDF
- 8. 從OpenXml生成PDF
- 9. iOS - 如何在風景中生成PDF
- 10. 在iOS中生成多個PDF頁面
- 11. Ionic在iOS和Android中生成pdf
- 12. 在ios上生成高分辨率pdf
- 13. UITableView不是從plist更新
- 14. 從Plist的UItableView數據
- 15. 加載plist在UITableView
- 16. iOS用Plist中的數據填充UITableView
- 17. 來自plist詞典的UITableView KEYS,iOS
- 18. 從plist文件生成PDF(帶有文本和圖像),是否可以完成?
- 19. IOS有一個報告生成器在PDF中生成
- 20. 如果可以從UITableView生成PDF文件?
- 21. iOS:將UITableView渲染爲PDF
- 22. Plist to UITableView
- 23. 的iOS:從plist中
- 24. UITableView中的UITableView與.plist
- 25. iOS PDF生成:如何在PDF中繪製MkMapView?
- 26. 從SVG生成PDF/paper js
- 27. 從Itext生成inputStream pdf源
- 28. 從頁面生成PDF
- 29. 從XML生成HTML和PDF
- 30. 從JSP頁面生成PDF?
http://stackoverflow.com/questions/4362734/ios-sdk-programmatic ally-generate-a-pdf-file – amar