LC DS 2.5 : Generating PDF from within a Flex application

March 23, 2007

Livecycle Data Services 2.5 (previously known as Flex Data Services) has got a new feature that will allow you to generate PDF files. Cool stuff certainly if look at the way we integrate a part of the Livecycle solution.

Adobe Livecycle allows you already a while to generate PDF based on a template and data (xml). The template is being build using Livecycle Designer. LC Designer offers you a WYSIWYG interface to build templates. The data(xml) you will be merging into the template is being displayed as a tree structure. By using drag and drop, you can link a data element with a visual control in the template. This solution is based on the XFA specification.

This functionality will now be available for Flex developers through LC Data Services. Your Flex application will have to generate a XML file, so LC DS can merge the XML data with your XFA template. (the template is being build with LC Designer). To build the XML within your flex application use the mx:XML tag. This makes life easy as you can just reference variables to fill up the XML.

<mx:XML id=”xmlModel”>
<CompanyReport>
<TitleText>{panel.title}</TitleText>
<OverviewText>{overviewText.text}</OverviewText>
<BalanceSheetImage>{balanceSheetImage}</BalanceSheetImage>
<EarningsImage>{earningsImage}</EarningsImage> </CompanyReport>
</mx:XML>

Nice thing is that you can put images into the XML and map them in the XFA template with an image control. And to make it complete, the ImageSnapshot actionscript object, allows you to create an image/screenshot from flex controls in your Flex application. Check out this code example …

var snapshot:ImageSnapshot = ImageSnapshot.captureImage(balanceSheet);
balanceSheetImage = ImageSnapshot.encodeImageAsBase64(snapshot);

You just have to reference the balanceSheetImage variable into the XML model. ImageSnapshot can take a snapshot from any UIComponent. Think especially on chart components that can be shown in PDF.

The actual creation of the PDF will happen on the server, by calling a Remote Object. You’ll have to create a POJO that will use the “flex.acrobat.pdf.XFAHelper” java object (part of LC DS). Here is an example on how this might look like …

example : calling the remote object in Flex

<mx:RemoteObject id=”service” destination=”PDFService” fault=”faultHandler(event)” result=”resultHandler(event)” />

// call the remote POJO method (as defined below), giving the XML model as an attribute … 
service.generatePDF(xmlModel);

example : java source code of object that calls XFAHelper

// define a string with a link to the XFA template
String source = FlexContext.getServletContext().getRealPath(“/pdfgen/company.pdf”);
XFAHelper helper = new XFAHelper();
helper.open(source);

// Import XFA dataset : dataset is the XML constructed in your Flex application. dataset is a org.w3c.dom.Document
helper.importDataset(dataset);

// Save new PDF as a byte array in the current session
byte[] bytes = helper.saveToByteArray();

Download the Livecycle DS beta from http://labs.adobe.com and try it out for yourself.

Don’t forget that this solution is generating the chart on the client. So this is not a solution for generating charts on the server and merge them with a XFA template. 

Here you can find an example of a PDF generated through LC DS.


Sun Tech Days in Paris and release Apollo alpha

March 22, 2007

I presented yesterday together with Michael Chaize to a bunch of java developers at SUN Tech Days here in Paris. We had about 250 people in the room and got great feedback. Java developers love our technology and the concept of Apollo.

Apollo alpha has been released for about 5 days and it’s impressive to see how many people already have been playing with it … We had about 10 java developers stepping up to us and talking about it. Also surprising to see the number of apollo apps that are already available … The coolest ones is the Apollo Finetunes client. I got it installed and totally love it ;)
Also yourminis.com came up with an apollo app that acts like a widget container … Another one to check out is Eli’s Apollo book … cool example that shows how Apollo allows us to combine flex and html.
Also the Apollo client for gmail is kind of interesting … This is a quite simple apollo app that will run the online google mail through the html component from Apollo, no Flex involved. It’s a 100% online experience as it’s online html. It is not the ideal Apollo application but a great way to get start. It can be the first step in a procces to build an Apollo application that will be able to run both online and offline. I expect you’ll see quite a few of these initiatives as i can imagine a lot of people like the fact that apollo makes your web application look like a real desktop application …

Anyway, I just have one advice … install it and get exited !


Adobe MAX conference coming to EMEA !

March 1, 2007

The dates and venues for MAX 2007 are public …

  • MAX North America: September 30-October 3, 2007, Chicago, IL
  • MAX Europe: October 15 – 18th 2007, Barcelona, Spain
  • MAX Japan: November 2007, Japan

This year MAX should certainly be the event to attend with Apollo coming up !

More details will appear soon on the Adobe website … I will post whenever registration for EMEA MAX will be available.

Website is available : http://www.adobemax2007.com/