我想用一些文本创建一个PDF。实际上我想要的是,如果它不包含在单个页面中,它将在另一个页面中继续。我正在给出一些我在项目中编写的代码。它适用于单页但不适用于多页。
CGContextRef pdfContext;
CFStringRef path;
CFURLRef url;
CFMutableDictionaryRef myDictionary = NULL;
path = CFStringCreateWithCString (NULL, [filename UTF8String],
kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath (NULL, path,
kCFURLPOSIXPathStyle, 0);
CFRelease (path);
myDictionary = CFDictionaryCreateMutable(NULL, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("MyApp Proposal"));
CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("MyApp for iPad"));
pdfContext = CGPDFContextCreateWithURL (url, &pageRect, myDictionary);
CFRelease(myDictionary);
CFRelease(url);
float originX = 20;
float originY = 40;
CGContextSelectFont (pdfContext, "Helvetica", 14, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
NSString *contractText= [[NSUserDefaults standardUserDefaults] valueForKey:@"contract"];
UIColor *colorContractText = [UIColor blackColor];
if(contractText != nil)
{
CGSize contractSize = [contractText sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12] constrainedToSize:CGSizeMake(580, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
[contractText drawInRect:CGRectMake(originX, originY, contractSize.width, contractSize.height) withAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:12],NSForegroundColorAttributeName:colorContractText}];
}
如果有人帮助我,我将不胜感激。我在等待回应。