Rich formatting for PDF's directly from Actionscript

I've blogged previously about the AlivePDF libraries which allow you to create PDF's directly from Actionscript.

I've been using them for a project and all was going well until we hit a limitation in the libraries. We can do rich formatting and we can do automatic line wrapping and pagination, but we can't do the both together.

Screenshot of generated pdf

This would have been an enormous problem if this was a piece of commercial software as we would be completely at the mercy of the creators. However, as it is Open Source we have access to the code and we can extend it as we see fit.

And that's exactly what we did. I've added a new version of the writeText() method called very imaginatively writeText2().

It takes the same parameters but instead of taking a standard string it will render a string that has html markup. I.e. you can put a <b> tag in and your text will be bold. Eg:

// This will write the following text with appropriate styling and word wrapping
pdf.writeText2 ( 15, 'A long <u>piece</u> of <b>text</b> in <center>1111 center 1111 2222 center 2222 3333 center 3333 <b>BOLD TEXT</b> 4444 center 4444</center>standard format that should wrap by the time I finish this. AAAAAAAAAAAAAAAABBBBBBBBBBBBCCCCCCCCCCCCCCAAA <i>Italic text</i>. <b>Some bold text</b>. And now for some <b><i>Bold and Italic Text</i></b>. And back to normal. Then a line break<br/> That\'s All.'   );

For the curious you can download a sample document generated by it.

It currently supports the following tags:

  • <b> Make it bold
  • <u> Underline it
  • <i> Make it italic
  • <center> Center it
  • <br /> Add a line break

The code still needs a some cleanup and more testing but it seems to be reliable now.

The two files that were changed are available for download. Or alternatively you can download the full version with changes included. Give it a try and let me know what you think.

Cheers, Mark Lynch

Job Vacancy Sydney AU - Graduate or Junior OO Programmer

We're looking for a Computer Science Graduate or similar with strong Object Oriented programming skills and the ability to grasp cutting edge technologies quickly.

If you are looking to work with the latest technogies and are a motivated self starter with a positive "can do" attitude this is the job for you. The ability to take problems and deliver solutions is a must.

There will be significant on the job learning as we are always pushing the boundaries and using the latest and greatest technologies. We are currently working on projects using Actionscript/Flex, ColdFusion, PHP, and Javascript, and are leveraging technologies such as VOIP, SMS, Instant Messenger (Jabber XMPP) to deliver cutting edge solutions.

Suitable applicants will have a Bachelors Degree in Computer Science or Engineering, or similar tertiary qualification. Remuneration commensurate with experience.

Responsibilities would include:

  • Developing new functionality for Asterisk and VOIP applications
  • Creating Rich Internet Applications with Adobe Flex
  • Creation of Desktop applications with Adobe AIR
  • Design and development of new Web applications

Must haves:

  • A robust foundation in Object Oriented programming
  • Demonstrated experience in at least one OO language
  • Motivation to learn and push the boundaries
  • Understanding of XHTML and CSS

Preferable:

  • Experience with PHP, ColdFusion, Farcry CMS, XML, Web Standards etc
  • Competency using linux-based tools (SSH, bash, etc)
  • Familiar with using source control tools (Subversion, etc)
  • Familiarity with Actionscript or Flash

This role may be full time, part-time or on a contract basis depending on the candidates skills and experience. You will be working in a casual workplace with flexible hours in the centre of Sydney.

If this sounds like the job for you email your resume to mark@lynchconsulting.com.au if interested - no agencies please.

Getting Flex 4.0 up and running on Ubuntu

I came across a blog entry today from Mike Morearty about the flex 4 source tree.

It also mentioned the swfdump tool which looked interesting

I downloaded it and went to the bin directory to try swddump but it didn't work straight away complaining about a missing jar file.

I thought this would mean a lot of pain to get it all compiling but I was very surprised. Here were the steps to get it working on Ubuntu 8.04 Hardy Heron.

Step 1

Get the code from the repository

This will check out the code to a directory called flex4 under your current directory. I'm assuming you have Subversion installed but if you don't you'll need to run this first.
sudo apt-get install subversion

Get the tools to compile flex

sudo apt-get install ant ant-optional sun-java6-jdk
That wasn't hard now was it?

Compile

Go into the correct directory and call "ant" which will use the build.xml to build it all.
cd flex4
ant

Some couple of minutes later you should get the following message

BUILD SUCCESSFUL
Total time: 2 minutes 41 seconds

Now you have a build of Flex4. Next step is to figure out how to configure Flex Builder to use the new compiler.

NOTE: This is not a finished version of Flex4 yet. Just the work in progress.

Cheers, Mark

CFMX "The Graphing service is not available" - solved

I've just completed setting up a new ColdFusion server on Ubuntu Server (I know it's not a supported config) and ran into the following problem when I went to the admin page:

The Graphing service is not available

A bit of googling turned up this Technote from Adobe which mentioned the same problem on RedHat Linux.

The redhat solution is also documented on Talking Tree but it doesn't cover Ubuntu.

For Ubuntu it's very simple - you need to install 3 libraries and you are good to go - one single line.

sudo apt-get install libXp6 libXt6 libXtst6

This will install a dozen or so packages - then restart ColdFusion and you have a shiny working install.

Cheers, Mark Lynch

CF 7.0.2 Cumulative Hotfix 2 breaks MySQL Multiple Queries

I've just spent a while figuring out a painful bug in CF and am posting here so that I can reference it from the Adobe bug tracker as I can't explain the problem in 2000 characters.

Summary of Problem

CF 7.0.2 Cumulative Hotfix 2 and 3 breaks the use of Multiple SQL statements with MySQL connectorJ connector.

This is a regression as it works perfectly in CF 7.0.2 and CF 7.0.2 with Cumulative hotfix 1.

I have tested the following configurations:

  • CF7.0.2 MySQL connectorJ 5.0.8 - works
  • CF7.0.2 hotfix 1 MySQL connectorJ 5.0.8 - works
  • CF7.0.2 hotfix 2 MySQL connectorJ 5.0.8 - broken
  • CF7.0.2 hotfix 3 MySQL connectorJ 5.0.8 - broken
  • CF7.0.2 MySQL connectorJ 3.1.10 - works
  • CF7.0.2 hotfix 1 MySQL connectorJ 3.1.10 - works
  • CF7.0.2 hotfix 2 MySQL connectorJ 3.1.10 - broken
  • CF7.0.2 hotfix 3 MySQL connectorJ 3.1.10 - broken

Steps to reproduce bug:

1. Set up a CF 7.0.2 Multiserver install with built in webserver

2. Download and install ConnectorJ JDBC driver for MySQL and install as per Adobe Technote http://www.adobe.com/go/6ef0253

3. Create a mysql database named "test" the and create a table with the following script:

CREATE TABLE `tbl_test` (
   `id`    int(11) AUTO_INCREMENT NOT NULL,
   `data`   varchar(50) NULL,
   PRIMARY KEY(`id`)
)

4. In CF Admin create a DSN named dsn_test with following settings

  • JDBC Url: jdbc:mysql://127.0.0.1:3306/test?allowMultiQueries=true
  • Driver Class: com.mysql.jdbc.Driver
  • Driver name: (leave blank)
  • username: (valid user for your db - default: root)
  • password: (valid password for your db - default: 'blank')
  • Place the following file in the /opt/jrun4/servers/cfusion/cfusion-ear/cfusion-war directory

MySQL driver version:
<cftry>
<cfset oDriver = createObject("java","com.mysql.jdbc.Driver")>
<cfoutput> #oDriver.getMajorVersion()#.#oDriver.getMinorVersion()#</cfoutput>
<cfcatch type="any">
   Unknown
</cfcatch>
</cftry>

<cfquery name="qTest" datasource="dsn_test">
   INSERT INTO tbl_test (data)
   VALUES ('Test String');
   SELECT LAST_INSERT_ID() as lastInsertID;
</cfquery>
<cftry>
<cfdump var='#qTest#'>
<cfcatch type="any">
   No Query set returned from query.
</cfcatch>
</cftry>

This code should function correctly and return a cfdump of the auto generated primary key as per expected screenshot.

Next apply Coldfusion Cumulative hotfix 2 and restart coldfusion as per Adobe Technote http://www.adobe.com/go/kb400996

Re run the test and no query set will be returned from the driver. The qTest variable does not get set as per the broken screenshot.

Related Resources

Technote re upgrading MySQL JDBC Drivers http://www.adobe.com/go/6ef0253

CF Updates page http://www.adobe.com/support/coldfusion/downloads_updates.html#mx7

CF 7.0.2 Cumulative hot 3 http://www.adobe.com/go/kb402465

CF 7.0.2 Cumulative hot 2 http://www.adobe.com/go/kb400996

CF 7.0.2 Cumulative hot 1 http://www.adobe.com/go/kb400074

MySQL ConnectorJ http://www.mysql.com/products/connector/j/

MySQL ConnectorJ 3.1.10 Download: http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-3.1.10.tar.gz/from/pick#mirrors

BlogCFC was created by Raymond Camden. This blog is running version 5.1.004.