ImageDrawText - Negative font sizes give text a new spin
I discovered today (completely by accident) that using a negative font size gives image text a whole new spin. It rotates the text 180 degrees. Similar code in java produces the same results. So it must be related to the underlying java classes.
The following ColdFusion code produces the image below.
Negative Font Size Example
<cfset img = ImageNew("", 200, 100)>
<cfset attr = { font="Arial", style="bold", size="-20" }>
<cfset ImageDrawText(img, "Transform Me", 190, 10, attr)>
<cfimage action="writeToBrowser" source="#img#">
The one code gotcha is the x coordinate. Since the text is rotated 180 degrees, the x coordinate is now relative to the right hand side. So if the desired x position is 10, you must use x = ImageGetWidth(img)-10 instead of x = 10.
Now I have not seen this documented anywhere. So I would use ImageRotateDrawingAxis instead. But it was still an interesting find ;)
Update: I corrected a typo in example/function name.
ImageRotateDrawingAxis
<cfset img = ImageNew("", 200, 100)>
<cfset ImageRotateDrawingAxis(img, 180, 100, 10)>
<cfset attr = { font="Arial", style="bold", size="20" }>
<cfset ImageDrawText(img, "Transform Me", 10, 10, attr)>
<cfimage action="writeToBrowser" source="#img#">
5 comments:
You have a great blog here! I've been using iText for a couple years in a java environment. Over the past few weeks I've been doing a CF project that required a little iText work, and your blog has been invaluable!!
I have a question for you. Have you tackled extending PdfPageEventHelper in CF?
@Lemonhead,
Thanks. I am very glad the CF examples were helpful :)
No, I have not. But you have piqued my curiosity. What are you trying to do with page events?
I use it to create page headers and footers.
Bruno has a tutorial at http://itextdocs.lowagie.com/tutorial/directcontent/pageevents/index.php
There is an example on the right hand side showing how to use the onEndPage to create headers and footers.
Yes, I was trying something similar right before I saw your comment. The example I created seems to work so far. I will post in a few .. for posterity ;)
@Lemonhead,
Here is the link Using iText's PdfPageEventHelper with ColdFusion.
Post a Comment