Advertise Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

sdkIQ for iPhone
($4.99)

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Dual Matches
($0.99)

Calcuccino Programmers' Calculator
($2.99)

SDKtoday
(free)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-22-2010, 04:22 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 4
Default 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
Omid is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Stats
Members: 41,860
Threads: 49,768
Posts: 213,052
Top Poster: BrianSlick (3,138)
Welcome to our newest member, gustavo7sexton
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:52 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0