Eric Brotto
Eric Brotto

Reputation: 54281

CGContext set text to justify right when generating a pdf

I'm using a series of CGContext commands to create text to be used for generating a pdf file:

CGContextSelectFont (pdfContext, "Helvetica", 14, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
CGContextSetTextMatrix(pdfContext, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));

I would like to right justify the text though. Any idea on how to do this? For example, is there a method that allows you to specify the origin as the top right corner of the text, not the top left?

    CGContextShowTextAtPoint (pdfContext, x, y, text, strlen(text));

Thanks!

Upvotes: 3

Views: 1071

Answers (1)

iPDFdev
iPDFdev

Reputation: 5834

Right and center justifications are not supported. In order to draw right aligned text, you need to compute the text width, subtract the text width from the right aligned x and then draw the text at the computed position.

Upvotes: 5

Related Questions