Generating PDF from Flex BarChart

Hello,
I am new to Flex. Have been playing with creating Advanced
Data Grid and Bar Charts for our application prototype and would
like to explore how to create a PDF file of the BarChart or other
charting components.
The requirement is simple. We show the BarChart and a button
to view it as a PDF. When the user presses the button, the PDF
viewing dialog should come up and the user can opt to save the PDF
or view it (the standard way a browser deals with the PDF).
Have read blogs, this forum and LiveCycle docs but don't
understand clearly how Flex communicates with
LiveCycle ES (or PDF Generator) to display the PDF. Any ideas
or tutorials that does this would be appreciated.
Thanks,
Kannan

In order to generate a PDF document, you have to call a
method on a Java remote object that uses the XFAHelper and pass it
some arguments.
I modified the PDFService example in the documentation so I
can:
1- specify any document as opposed to hardcoding the PDF
template name
2- write the PDF to a file as opposed to writing it in the
user's session
Here is the source:
package com.mycompany.flex.remoteObjects;
import java.io.File;
import java.io.IOException;
import org.w3c.dom.Document;
import flex.acrobat.pdf.XFAHelper;
import flex.messaging.FlexContext;
import flex.messaging.util.UUIDUtils;
public class PDFService
public PDFService()
public Object generatePDF(Document dataset, String
PDFdocument) throws IOException
// Open shell PDF
String source =
FlexContext.getServletContext().getRealPath("/pdfgen/" +
PDFdocument);
int index = source.indexOf("./");
if(index != -1 )
// Remove the ./ added by UNIX
source = source.substring(0, index) + source.substring(index
+ 2, source.length());
XFAHelper helper = new XFAHelper();
helper.open(source);
// Import XFA dataset
helper.importDataset(dataset);
// Create a unique ID
String uuid = UUIDUtils.createUUID(false);
source =
FlexContext.getServletContext().getRealPath("/dynamic-pdf/" + uuid
+ "_" + PDFdocument);
index = source.indexOf("./");
if(index != -1 )
// Remove the ./ added by UNIX
source = source.substring(0, index) + source.substring(index
+ 2, source.length());
// Create the file object
File file = new File(source);
// Save the file
helper.save(file);
// Close any resources
helper.close();
return (uuid + "_" + PDFdocument);
pdfgen is the folder where my PDF template resides.
dynamic-pdf is the folder where the generated PDF are saved.
These two folders are located under flex.war at the first
level.
In Flex, I wrote a Cairngorm command that calls this remote
object and displays the generated PDF:
package com.mycompany.core.commands
import com.adobe.cairngorm.commands.ICommand;
import com.adobe.cairngorm.control.CairngormEvent;
import com.adobe.cairngorm.business.Responder;
import
com.mycompany.core.business.GenerateAndOpenPDFDelegate;
import
com.mycompany.core.control.event.GenerateAndOpenPDFEvent;
import com.mycompany.core.model.ModelLocator;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.collections.*;
import mx.core.Application;
import mx.controls.Alert;
public class GenerateAndOpenPDFCommand implements ICommand,
Responder
[Bindable]
private var model:ModelLocator = ModelLocator.getInstance();
public function GenerateAndOpenPDFCommand():void
public function execute(event:CairngormEvent):void
trace("Executing GenerateAndOpenPDFCommand...");
var delegate : GenerateAndOpenPDFDelegate = new
GenerateAndOpenPDFDelegate( this );
var generateAndOpenPDFEvent : GenerateAndOpenPDFEvent =
event as GenerateAndOpenPDFEvent;
delegate.generateAndOpenPDF( generateAndOpenPDFEvent.pdfVO
public function onResult( event : * = null ) : void
var item:Object;
var result:String = (event as ResultEvent).result as String;
trace("GenerateAndOpenPDFCommand::onResult\n\n" + result);
if (result)
// Open the generated PDF in a new window
navigateToURL(new URLRequest(ModelLocator.FLEX_URL +
"dynamic-pdf/" + result), "_blank");
// Hide the progress bar overlay
Application.application.requestProgressBar.visible = false;
Application.application.requestProgressBar.progressBar.source =
null;
Application.application.requestProgressBar.progressBar.label
= this.model.languageDictionary["000012"];
public function onFault( event : * = null ) : void
// Hide the progress bar overlay
Application.application.requestProgressBar.visible = false;
Application.application.requestProgressBar.progressBar.source =
null;
// Debug
Alert.show("GenerateAndOpenPDFCommand:\n\n" + (event as
FaultEvent).message);
FLEX_URL is created in this way some place else in the
application:
// Get the server URL from the Application's
var server:String = Application.application.url;
var index:uint = server.indexOf("Shell"); // Shell is the
name of my app folder
server = server.substring(0, index);
// This is the flex.war/ URL
ModelLocator.FLEX_URL = server;
Of course, it would be better to save the PDF in the user's
session as Adobe suggests, but I couldn't figure out how they use
the PDFResourceServlet. First of all, I had to get its code.
I had to decompile the java class files in the samples to get
the source of the PDFResourceServlet as it is not in the
documentation. Here it is:
package com.mycompany.flex.remoteObjects;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class PDFResourceServlet extends HttpServlet
public PDFResourceServlet()
protected void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
doPost(req, res);
protected void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
String id = req.getParameter("id");
if(id != null)
HttpSession session = req.getSession(true);
try
byte bytes[] = (byte[])(byte[])session.getAttribute(id);
if(bytes != null)
res.setContentType("application/pdf");
res.setContentLength(bytes.length);
res.getOutputStream().write(bytes);
} else
res.setStatus(404);
catch(Throwable t)
System.err.println(t.getMessage());
private static final long serialVersionUID =
0x7180e4383e53d335L;

Similar Messages

  • Generate PDF From Flex

    Hi All,
    I am doing a Reporting/Chart application in FLEX. we need to
    generate PDF from FLEX. Report data will be 5-10 pages, How we can
    do this? Please advise.
    Thanks
    Subhash

    Hi,
    thanks for your reply. I tried with alive pdf, but source
    code only AIR files. can we use this in web based flex?. How we can
    format the report like html code? I just see in alivepdf, its only
    linebyline display, not multiple columns? pls advise.
    thanks alot
    Subhash

  • Generating pdfs from Flex

    I'd like to generate pdf files from Flex. How is this done? How much does it cost? How flexible is it?

    http://lucamezzalira.com/2009/02/28/create-pdf-in-runtime-with-actionscript-3-alivepdf-zin c-or-air-flex-or-flash/ checkout this link..can be done freely

  • Generate report from flex

    If its possible to generate report from flex.Please help me

    Hi,
    thanks for your reply. I tried with alive pdf, but source
    code only AIR files. can we use this in web based flex?. How we can
    format the report like html code? I just see in alivepdf, its only
    linebyline display, not multiple columns? pls advise.
    thanks alot
    Subhash

  • JNDI error while generating pdf from crystal reports in java

    Hi, i want to generate PDF from crystal reports in java. I have the .PDF file with database configured into the report. Following details are available in report.
    1. Server Name      = testdb
    2. Database Name  = testdb
    3. User
    4. Password
    I am using CR XI.
    In CRConfig.xml i had given following details.
    <JDBC>
         <CacheRowSetSize>100</CacheRowSetSize>
         <JDBCURL>jdbc:oracle:thin:@192.218.216.102:1521://TESTDB</JDBCURL>
         <JDBCClassName>oracle.jdbc.driver.OracleDriver</JDBCClassName>
         <JDBCUserName>user</JDBCUserName>
         <JNDIURL>password</JNDIURL>
         <JNDIConnectionFactory></JNDIConnectionFactory>
         <JNDIInitContext>/</JNDIInitContext>
         <JNDIUserName>testdb</JNDIUserName>
         <GenericJDBCDriver>
              <Default>
                   <ServerType>UNKNOWN</ServerType>
                   <QuoteIdentifierOnOff>ON</QuoteIdentifierOnOff>
                   <StoredProcType>Standard</StoredProcType>
                   <LogonStyle>Standard</LogonStyle>
              </Default>
         </GenericJDBCDriver>
    </JDBC>
    When i am calling from java as standalone, i am getting following error.
    JRCAgent1 detected an exception: Error finding JNDI name (testdb)
    at com.crystaldecisions.sdk.occa.report.lib.ReportSDKException.throwReportSDKException(Unknown Source)      at com.businessobjects.reports.sdk.b.i.if(Unknown Source)
    Can anyone let me know where is the problem?

    Actually, the question boils down to; does the framework support the fonts?
    I believe that my question re. this working in the designer was valid. The designer does not use the framework, so if it works there, it is either a framework issue or a runtime print engine issue.
    I believe if you use the code below, it will list fonts available to the framework:
    foreach(FontFamily ff in FontFamily.Families)
    System.Diagnostics.Debug.WriteLine(ff.Name);
    For more information see kbase [1198306 - Crystal Report displaying incorrect font in Microsoft Visual Studio .NET|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_dev/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333133393338333333303336%7D.do]
    Ludek

  • Generating PDF from Microsoft Word with C#

    Hello,
    We have created web-based system for a customer that stores/handles Microsoft word documents and provides these to users as PDF versions. Unfortunately some problems appear with our third-party component that generates PDF from Word. Our customer has previously used Adobe Acrobat X Pro to manually generate the PDF files and is confident that the output produced this way is valid. Despite searching and reading a lot I can't find any way to determine if (and how) it is possible to automate the process of generating a PDF file from a Microsoft word file using the Adobe engine. There is a lot of SDK documentation, how to control PDF rendering in winforms applications etc. etc. All I want to do is to load an Adobe Acrobat instance, feed it with a word document and save it as a PDF on disk. From a C# app (ASP.NET). Is that possible?
    Best regards
    Jan Hansen

    As mentioned, you can probably send the DOC file to the Adobe PDF printer to create the file. What I keep reading in your post is a legal issue. You keep mentioning being able to create the PDF on a server automatically. The server use of Acrobat is a violation of the EULA. If you are creting the files off-line for posting as has been done, there should not be a problem. However, having these created in an automated manner by the user may be an issue. Before you go much further, I would check with legal counsel about the use of Acrobat in the way you intend. If they indicate there is a problem, then your question is not needed.
    Back to the issue. Try just dropping a DOC file on the Adobe PDF printer icon (you may have to open the Start>Printers to do that. See if that creates the PDF. If so, you will just need to automate that process.

  • Gray box for logo generating pdf from fm book

    Greetings,
    I have a large FrameMaker book that I've generated pdfs from a million times. We cleaned up our logo, so I dropped it in and tried to generate the usual pdf. a gray box resulted for the logo only. all other artwork displayed fine. i tried scaling down the logo, changing formats, changing import methods, etc. all failed. however, generating a pdf from the book if I remove a few chapters gives me my logo. Am I running out of resources? I'm using tech comm suite 1.3 on vista. There are no clues in the acrobat log. show large images is turned on in the adobe reader.
    I used the obvious workaround: generated two pdfs, one with just the logo page and one with the rest of the book, then combined them. But this process is not practical long term. Any clues?

    A couple questions:
    What format is the new logo file?
    Given that it works with some component files, but not in the book... I'd guess that it may be a resource issue. How much RAM and free space do you have?
    And when you "dropped it in," does that mean imported into one file by reference, or copied in, or imported into a template that you used to update all files in the book..... or something else? And if it did update multiple files, did you double-check them to make sure the path to the graphic is correct?

  • Generating PDF from MSWord--IsTable of Content Updated?

    Hello,
    In generating PDF from MSWord document does the Adobe process call a method on the MSWord object to update the TOC field in the Word document during the generation process. Or is it assumed that the table of content in the Word document is always updated. If the table of content field is not current, field error message can appear in the Word document and the page number for
    the link can contain inaccurate values.
    Thank you,
    Jesse

    It is assumed the TOC is up to date.

  • Generating pdf from scanner

    generating pdf from scanner hp G3010: old windows xp file weight 40-50 K. Macbook pro with new mac os 10.7.2 minimum file weight 1,9 Mbyte with terrible resolution!!!! and no way to reduce.
    Nice change?

    It is assumed the TOC is up to date.

  • I am able to generate PDF from Framemaker file but not able to generate pdf from book in robohelp

    Hi,
    Using robo help i am able to generate pdf  from a single framemaker file.
    but when i am importing whole book then i am not able to make it.
    And also it is not showing any error on console
    It goes to hang like situation and i have to close it from task maneger.

    Ok, silly question - why are you bothering to try and create PDFs from RH when you've got FM? FM to PDF produces great results; RH to PDF involves having to go through Word - i.e. RH - Word - PDF = too much work IMHO.

  • Conversion of PDF from flex

    Hai
       I need to create pdf generation from flex.
       I tried with LCDS and there is no way to create XDP template.
       live cycle designer needs dotnet support.. but i need to do with j2ee..
       is any other approach to create pdf from flex with j2ee environment???
       thanks in advance...

    Hi there, there's a library called AlivePDF that allows you to create pdf files from Flex. Maybe that's what you're looking for.

  • How I Got WYSIWYG TLF Text To PDF from Flex

    Awesome results read more here:  http://hybridmindset.com/blog/How-I-Got-WYSIWYG-TLF-Text-To-PDF-from-Flex-Part-1

    Hi,
    Adobe Reader currently doesn't support Text to Speech, but we have added this to our database for consideration in a future release.
    Thanks for your feedback!
    -Gaurav

  • How to generate PDF from template via REST query

    Hello. I'm newbie in Adobe LiveCycle, will appreciate any help.
    What we need: generate PDF from template, using different data.
    What we have: LiveCycle Designer and server with deployed Adobe LiveCycle ES 2.5 image.
    Looks like server works and listen 8080.
    In Livecycle Designer I can generate XML (XDP) from PDF, so I can change this XML in PHP/Python/Go script to fill template with data.
    I'm looking for some REST method, where I can give that XML (XDP) and recieve generated PDF in response.
    I've spent whole to for googling all these things, found a lot of docs, but all is very complicated there. Also, examples from just doesn't work - maybe I have to do something on server before calling REST API method.
    Please, push me into right direction

    Your best bet is to probably create an orchestration (or "process" in Adobe speak) that accepts two document parameters, calls LiveCycle Forms (or Output depending on whether you want to interactive or non-interactive PDF), and returns the resulting document variable.
    The orchestration will return a redirect that will point you to the document object.
    See Invoking LiveCycle using REST Requests, and Creating Your First LiveCycle ES4 Application.
    Rob

  • Generate PDF From Database

    Hi,
    I have a table in database. Table has a column. There is data of pathes of images into column. I cretaed a illustrator template and I want to generate PDF from this template with using table data in database. so, is it possible? illustrator created pdf per each image with using illustrator template.
    thanks,

    AI cannot conent directly to databases. It can only parse CSV/ XML data. You either need to export the stuff or create extensive scripts to connect to the life database using sockets.
    Mylenium

  • Can't generate PDF from xdp and XML

    Hello,
    I'm new to livecycle and flashbuilder.
    I assigned as a task to send to a  livecycle server a xdp template and a XML file with the data in order to create the pdf.
    So far, I created a class with two methods that returns as a BLOB the strings of a xdp template and the XML data to populate the template.
    On the main application I'm calling the generatePDFOutput method from the OutputService and as far as I know I'm supposed to get a Blob which I can manipulate to save it as a PDF.
    What could be my error? or how should I approach this problem? I came here since I can't find some document that shows how to create pdf from a flex app using livecycle...
    I appreaciate your help.
    I attach below the code of the main class
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="initializeChannelSet();">
        <fx:Script>
            <![CDATA[
                import flash.sampler.Sample;
                import mx.messaging.ChannelSet;
                import mx.messaging.channels.AMFChannel;
                import mx.rpc.CallResponder;
                import mx.rpc.events.ResultEvent;
                import services.outputservice.OutputService;
                import valueObjects.BLOB;
                import valueObjects.OutputResult;
                import valueObjects.PDFOutputOptionsSpec;
                import valueObjects.RenderOptionsSpec;
                private var parentResourcePath:String="/";
                private var serverPort:String="192.168.3.46:8080";
                private function initializeChannelSet():void{
                    var cs:ChannelSet= new ChannelSet();
                    cs.addChannel(new AMFChannel("remoting-amf", "http://"+serverPort+"/remoting/messagebroker/amf"));
                    outputService.setCredentials("administrator","password");
                    outputService.channelSet=cs;
                protected function btn_clickHandler(event:MouseEvent):void
                var pdf:OutputService= new OutputService();
                var x:TestPDF= new TestPDF();
                var wsCall:CallResponder= new CallResponder();
                var out:PDFOutputOptionsSpec= new PDFOutputOptionsSpec();
                out.fileURI="D:\PDF_Output\test.pdf";
                var render:RenderOptionsSpec= new RenderOptionsSpec();
                wsCall.token=pdf.generatePDFOutput("PDF","Form.xdp","D:\\PDF_Output",out,render,TestPDF.D ata());
                var res:BLOB= wsCall.lastResult as BLOB;
                var result:ByteArray= new ByteArray();
                    result=res as ByteArray;
                var a:Number=2;
                protected function outputService_resultHandler(event:ResultEvent):void
                    // TODO Auto-generated method stub
            ]]>
        </fx:Script>
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
            <mx:RemoteObject id="outputService" destination="OutputService" result="outputService_resultHandler(event);"/>
        </fx:Declarations>
        <s:Button id="btn" x="90" y="141" label="Button" click="btn_clickHandler(event)"/>
    </s:Application>

    build.xml file for Hibernate:
    <?xml version="1.0"?>
    <project name="Hibernate"
    default="schemaGenerator" basedir="C:\Hibernate">
    <property name="src.dir" value="src"/>
    <property name="classes.dir" value="classes"/>
    <property name="hibernate" value="hibernate-2.1"/>
    <property name="hibernate.mappings" value="mappings"/>
    <property name="jdbc" value="C:\oracle\product\10.1.0\Db_1\jdbc"/>
    <property name="hibernate.extensions" value="tools"/>
    <property name="hibernate.properties" value="properties"/>
    <path id="project.class.path">
    <pathelement location="${classes.dir}" />
    <fileset dir="${hibernate}">
    <include name="hibernate2.jar"/>
    </fileset>
    <fileset dir="${hibernate}/lib">
    <include name="*.jar"/>
    </fileset>
    <fileset dir="${hibernate.extensions}/lib">
    <include name="*.jar"/>
    </fileset>
    <fileset dir="${hibernate.extensions}">
    <include name="hibernate-tools.jar"/>
    </fileset>
    <fileset dir="${jdbc}/lib">
    <include name="classes12.jar"/>
    </fileset>
    </path>
    <target name="init"> <mkdir dir="${src.dir}"/>
    <mkdir dir="${classes.dir}"/>
    </target>
    <taskdef name="javaGen"
    classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
    classpathref="project.class.path"/>
    <target name="javaGenerator" depends="init">
    <javaGen output="${src.dir}">
    <fileset dir="${hibernate.mappings}">
    <include name="Catalog.hbm.xml"/>
    </fileset>
    </javaGen>
    </target>
    <target name="compile" depends="javaGenerator">
    <javac srcdir="${src.dir}"
    destdir="${classes.dir}">
    <classpath refid="project.class.path"/></javac>
    </target>
    <taskdef name="schemaGen"
    classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
    classpathref="project.class.path"/>
    <target name="schemaGenerator" depends="compile">
    <schemaGen properties="${hibernate.properties}/hibernate.properties" quiet="no">
    <fileset
    dir="${hibernate.mappings}">
    <include name="Catalog.hbm.xml"/>
    </fileset>
    </schemaGen>
    </target>
    </project>

Maybe you are looking for

  • Photoshop Elements 7 Editor crashes upon opening any image

    I have been trying for 2 days to get my Photoshop to work. I've used PSE7 for years, no issues. Suddenly yesterday, every time I try to open an image in the full editor, I get the "Photoshop has stopped working... check online for a solution or close

  • Saving and Backing Up

    Hi, 1) How best can I protect my sequences so that if it gets corrupt I can go back to yesterdays? In Pro Tools I'd open my session each day and change the date so if I goofed anything up I can always go back to yesterdays and begin again from there.

  • To find whether the attachment exists for DIR ( Document Info Record )

    Sir We are using DMS to link the Documents pertians to Project . Documents are  having the Drawing PDF attachments . How to track whether there is attachment exists or Not ? ( We have chakced the DRAW & DRAD but no attachment related infomation is ob

  • Internet based apps are crashing

    I have reset network and reset all settings to no change.  I can access and send email though??? Help

  • FIrefox repeatedly crashes at startup or just after opening a webpage

    Firefox repeatedly crashes on startup or just after opening a new page, I've tried downgrading my browser to FF 18 & the problem still occurs. Firefox won't even run properly in safe mode. I have included the latest crash report: bp-d8715a6c-6208-442