+(void) CreatePDFFileWithPageSize: (CGRect) pageRect
Image: (CGImageRef) image
ImagePosition: (CGRect) imgPos
Border: (CGImageRef) border
TextToDisplay: (const char *) text
TextPosition:(CGRect) txtPos
TextAngle:(CGFloat) currentAngle
TextFont:(UIFont *) txtFont
Icons:(NSMutableDictionary *) iconsDict
Path: (const char *)filename;
{
// This code block sets up our PDF Context so that we can draw to it
CGContextRef pdfContext;
CFStringRef path;
CFURLRef url;
CFMutableDictionaryRef myDictionary = NULL;
// Create a CFString from the filename we provide to this method when we call it
path = CFStringCreateWithCString (NULL, filename,
kCFStringEncodingUTF8);
// Create a CFURL using the CFString we just defined
url = CFURLCreateWithFileSystemPath (NULL, path,
kCFURLPOSIXPathStyle, 0);
CFRelease (path);
// This dictionary contains extra options mostly for 'signing' the PDF
myDictionary = CFDictionaryCreateMutable(NULL, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("..."));
CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("..."));
CFDictionarySetValue(myDictionary, kCGPDFContextKeywords, CFSTR("..."));
// Create our PDF Context with the CFURL, the CGRect we provide, and the above defined dictionary
pdfContext = CGPDFContextCreateWithURL (url, &pageRect, myDictionary);
// Cleanup our mess
CFRelease(myDictionary);
CFRelease(url);
// Done creating our PDF Context, now it's time to draw to it
// Starts our first page
CGContextBeginPage (pdfContext, &pageRect);
//!!!: draw image
float newY = pageRect.size.height - (imgPos.origin.y + imgPos.size.height);
CGContextDrawImage (pdfContext, CGRectMake(imgPos.origin.x, newY, imgPos.size.width, imgPos.size.height),image);
...
//!!!: draw rendered Text
newY = pageRect.size.height - (txtPos.origin.y /*+ txtPos.size.height*0.75*/);
UIGraphicsPushContext(pdfContext);
CGContextTranslateCTM(pdfContext,txtPos.origin.x, newY);
CGContextScaleCTM(pdfContext, 1.0, -1.0);
CGAffineTransform textTransform = CGAffineTransformMakeRotation(/*M_PI*2 - */currentAngle);
CGContextConcatCTM(pdfContext, textTransform);
NSString *string =[NSString stringWithCString:text];
//[string drawInRect:CGRectMake(0, 0, txtPos.size.width, txtPos.size.height) withFont:[UIFont fontWithName:@"Helvetica" size:48]];
[string drawInRect:CGRectMake(0, 0, txtPos.size.width, txtPos.size.height) withFont:txtFont];
UIGraphicsPopContext();
// We are done drawing to this page, let's end it
// We could add as many pages as we wanted using CGContextBeginPage/CGContextEndPage
CGContextEndPage (pdfContext);
// We are done with our context now, so we release it
CGContextRelease (pdfContext);
}