 |
 |
|
 |
02-22-2010, 04:22 AM
|
#1 (permalink)
|
|
Registered Member
Join Date: Jan 2009
Posts: 4
|
Draw Text in PDF context (with a given angle)
Hi all,
I trying now some days to position an given text into a pdf contect by a given position and angle. But my positioning seems not to be correct.
Here is the way I do it:
Code:
- (IBAction)createPDF:(id)sender {
...
CGPoint curTxtPos = [self.view.window convertPoint:lblMessage.frame.origin toWindow:nil];
...
[PDFController CreatePDFFileWithPageSize: CGRectMake(0, 0, 480, 320)
Image: imgSelectedImage.image.CGImage
ImagePosition: curImgPos
Border: (imgBorderImage.hidden)?nil:imgBorderImage.image.CGImage
TextToDisplay: [lblMessage.text cStringUsingEncoding:NSMacOSRomanStringEncoding]
TextPosition: CGRectMake(curTxtPos.x, curTxtPos.y, lblMessage.frame.size.width, lblMessage.frame.size.height)
TextAngle: txtAngle
TextFont: [lblMessage font]
Icons: iconsDict
Path: filenamepdf];
the CreatePDFFileWithPageSize looks like this:
Code:
+(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);
}
I really don't know where my failure is.
Thanks for your help,
Omid
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 383 |
| 27 members and 356 guests |
| AdamSubach, airsoft808, anonymous@, benoitr007, bensj, Danneman, Duncan C, gtyt38, gustavo7sexton, HemiMG, Jeremy1026, lifeCoder45, maxus182, mox, Ovidius, Paul10, pofak, qilin, raheel, Sega dude, squidboy, timle8n1, ufbobbo, ultrayard077, ZunePod |
| Most users ever online was 965, 06-30-2010 at 04:26 AM. |
» Stats |
Members: 41,860
Threads: 49,768
Posts: 213,052
Top Poster: BrianSlick (3,138)
|
| Welcome to our newest member, gustavo7sexton |
|