aman0711

save as PDF and image on jsp

Recommended Posts

Hi Experts,

 

 

 

I just got the V3.1 version and Want my charts to have save as image and save as pdf functionality. In your last version, I used to have your FusionChartsSave.jsp then two tags in the Chart tag(imageSaveURL and imageSave), which always did the trick. I tried using the same on my code this time and once the the data capturing part got to 100%, a white blank page was returned.. am I missing something?

 

 

 

I saw some posts regarding this functionality in 3.1 which I already have. Can you please describe in detail how to use it in my application.

 

 

 

I didnt get this peace of code below:

 






FusionCharts Export Handler Component



 

 

 

I never saw this line before either. var myExportComponent = new FusionChartsExportObject("fcExporter1", "../../FusionCharts/FCExporter.swf");

 

 

 

 

 

I am using the createChart method to render the chart. I would highly appreciate if you can tell me the instructions to implement these feature from grass root level.

 

 

 

BELOW is the code we are using to generate our charts currently:

 


<%

Connection conn = null;

Class.forName("oracle.jdbc.driver.OracleDriver");

conn = DriverManager.getConnection("jdbc:oracle:thin:@","user","pass");

%>



<%-- Fusion Chart XML creation using dataXML method --%>



<%

  String strXml="";

  String strQuery1="", strQuery2="", strQuery3="", strQuery4="", cat="", dataset1="", dataset2="", dataset3="", dataset4="";

  strXml="";

  try{

 Statement st1, st2, st3, st4;

 ResultSet rs1, rs2, rs3, rs4;

strQuery1= "Select * from  VSLAND.APM_WEB_12MONTH_APPGRP_V WHERE APP_GROUP='EBILL' ORDER BY DECODE(UPPER(MONTH), 'JAN', 7, 'FEB', 8, 'MAR', 9, 'APR', 10, 'MAY', 11, 'JUN', 12, 'JUL', 1, 'AUG', 2, 'SEP', 3, 'OCT', 4, 'NOV', 5, 'DEC', 6)";

strQuery2= "Select * from VSLAND.APM_WEB_12MONTH_APPGRP_V WHERE APP_GROUP='EDD' ORDER BY DECODE(UPPER(MONTH), 'JAN', 7, 'FEB', 8, 'MAR', 9, 'APR', 10, 'MAY', 11, 'JUN', 12, 'JUL', 1, 'AUG', 2, 'SEP', 3, 'OCT', 4, 'NOV', 5, 'DEC', 6)";

strQuery3= "Select * from VSLAND.APM_WEB_12MONTH_APPGRP_V WHERE APP_GROUP='KANAC' ORDER BY DECODE(UPPER(MONTH), 'JAN', 7, 'FEB', 8, 'MAR', 9, 'APR', 10, 'MAY', 11, 'JUN', 12, 'JUL', 1, 'AUG', 2, 'SEP', 3, 'OCT', 4, 'NOV', 5, 'DEC', 6)";

strQuery4= "Select * from VSLAND.APM_WEB_12MONTH_APPGRP_V WHERE APP_GROUP='QuickPay' ORDER BY DECODE(UPPER(MONTH), 'JAN', 7, 'FEB', 8, 'MAR', 9, 'APR', 10, 'MAY', 11, 'JUN', 12, 'JUL', 1, 'AUG', 2, 'SEP', 3, 'OCT', 4, 'NOV', 5, 'DEC', 6)";





st1=conn.createStatement();

rs1=st1.executeQuery(strQuery1);





while(rs1.next()){

    cat += ""; 

    dataset1 +="";

}



 rs1.close();

 st1.close(); 



 st2=conn.createStatement();

 rs2=st2.executeQuery(strQuery2);

 while(rs2.next()){

//   cat += ""  ;

    dataset2 +="";

}



 rs2.close();

 st2.close();



 st3=conn.createStatement();

 rs3=st3.executeQuery(strQuery3);

 while(rs3.next()){

//   cat += ""  ;

    dataset3 +="";

}



 rs3.close();

 st3.close();





 st4=conn.createStatement();

 rs4=st4.executeQuery(strQuery4);

 while(rs4.next()){

//   cat += ""  ;

    dataset4 +="";

}



 rs4.close();

 st4.close();





  }catch (Exception e){} 



strXml += " "+cat+"";



strXml += " "+dataset1+" "; 



strXml += " "+dataset2+" "; 



strXml += " "+dataset3+" "; 



strXml += " "+dataset4+" "; 





strXml += "";



out.print(strXml);



String chartCode=createChart("../FusionCharts/MSLine.swf", "", strXml, "SLA", 745, 300, false, false);

%>

<%

conn.close();

%>

<%=chartCode%>

 

 

 

Please tell me the reason why currently I am only using a white screen after the data capture process is done.

Edited by Guest

Share this post


Link to post
Share on other sites

Hi,

 
We have implemented a new image saving mechanism by which you can export chart to image or PDF either at client side at server side.
 
And the following code renders the "FusionCharts Export Handler Component", which is necessary when you are using client side exporting:
 
<!-- We also create a DIV to contain the FusionCharts client-side exporter component -->

<div id="ffffffcexpDiv" align="center">FusionCharts Export Handler Component</div>

<script type="text/javascript">

  //Render the export component in this

  //Note: fcExporter1 is the DOM ID of the DIV and should be specified as value of exportHandler

  //attribute of chart XML.

  var myExportComponent = new FusionChartsExportObject("fcExporter1", "../../FusionCharts/FCExporter.swf");

 
  //Render the exporter SWF in our DIV fcexpDiv

  myExportComponent.Render("fcexpDiv");

</script>

 
Also please refer to http://www.fusioncharts.com/docs/ >> Exporting as Image/PDF section to get more detail information on the same.
Edited by Guest

Share this post


Link to post
Share on other sites

Hi Rahul,

 

 

 

Few things I am real confused about:

 

 

 

1. Where do I need to declare this new code you told me about in your last post.

 

2. do I need to get Version 3.1 swf files for all the charts or even the older version ones will work?

 

3. Is there any special jars I need to put in my application. I am running Tomcat 6 on jdk 1.5

 

 

 

Your reply is highly appreciated and urgently needed :)

 

 

 

 

 

Regards

 

Aman

Share this post


Link to post
Share on other sites

Hi Aman,

The "single-jsp save as image" method, from the earlier versions, was simple but not comprehensive. With the newer mechanism of server side and client side export, you can save the chart as png, jpg, gif or pdf too.

Let me try to summarize the steps in getting the jsp server-side export feature up and running:

  1. Copy the following files to your server:

    Copy the jsps to your web application ( say root folder )

      1. FCExporter.jsp

      2. FCExporterError.jsp

      3. Resources/FCExporter_IMG.jsp ( copy the Resources folder also )

      4. Resources/FCExporter_PDF.jsp( copy the Resources folder also )

    Copy the jar file to WEB-INF/lib folder

      5. fcexporter.jar (contains all the dependency classes)

    Copy the properties file to WEB-INF/classes folder

      6. /Classes/fusioncharts_export.properties (configuration files)

  2. Add XML Attributes related to Export Feature:

    exportEnabled='1' exportHandler='FCExporter.jsp' exportAtClient='0' exportAction='download' exportFileName='MyFileName'

     

    You can get the complete list of attributes and how to use the server side export feature in these doc pages,

    http://www.fusioncharts.com/docs/Contents/ECServerDownload.html

     

    http://www.fusioncharts.com/docs/Contents/ECServerSave.html

  3. Modify properties file if required

    For example, you might want to change the path on the server where the images will be saved.

    The property for this SAVEPATH is shown below.

    #Please specify the path to a folder (with write permissions) relative to web application root

    #The exported image/PDF files would be saved here.

    SAVEPATH=./images/

Please do not hesitate to contact me in case you get stuck in any of these steps.

Hope this helps :)

Srividya

Share this post


Link to post
Share on other sites

Hey Srividya,

 

 

 

Thanks for such a detailed reply :-) Really very helpful, but still stuck with some problem :)

 

 

 

ok, so I followed all your steps, but when I right click on the chart, I am not seeing any option such as save as pdf or save as image.

 

I have attached the snapshot of my folder structure, Generated chart XML, the backend code that generates the chart XML.

 

PS: All the my static content is accessed with following path:

 

 

 

 

 

 

I am very sure, this problem is related to path issues.. have attached all the details.. please help me out, more like an urgent problem :(

 

 

 

Thanks in advance Srividya :D

 

 

 

Regards

 

Aman

MSColumn2DXmlBuilder.txt

post-3394-128441573328_thumb.jpg

chart XML.txt

Share this post


Link to post
Share on other sites

If you are wondering whether Resources folder contains the correct files then I have to say YES :)

 

 

 

Resources folder has:

 

 

 

FCExporter_IMG.jsp

 

FCExporter_PDF.jsp

 

 

 

Just forgot to expand this folder in snapshot :D

Share this post


Link to post
Share on other sites

Hi Aman,

I have checked your xml and the folder structure. They seem to be fine. I have tested the xml and it works fine- Save as jpeg etc are shown in the context menu.

If you are not getting the export related menu items, then I doubt the version of the swf file is below 3.1

Please verify the version of the swf file ( MSColumn2D.swf )

To see the version of the swf file, turn the debug mode on.

In the debug mode, the version of the file is displayed.

Hope this helps.

Srividya

Share this post


Link to post
Share on other sites

Hi Srividya,

 

 

 

Little improvement. I did change the swf files and now I can see the options to save. I am not able to see any image or pdf after the data capturing is done. All I am getting is a blank page with the following URL:

 

 

 

http://localhost:8080/analytics/static/Fusion/FusionCharts/FCExporter.jsp

 

 

 

which means it is even getting to the FCExporter.jsp, What problem is it facing to render the image or pdf?

Share this post


Link to post
Share on other sites

I changed the structure Srividya, Attached is the snap. replaced it with localhost... but I can still only see a blank :

FCExporter.jsp

Do you think this code is creating trouble?

StringBuffer err_warn_Codes = [b]new[/b] StringBuffer();
String WEB_ROOT_PATH = application.getRealPath("/");
String pathSeparator = File.separator; // will return either "" or "/", depends on OS
String validation_def_filepath = WEB_ROOT_PATH+pathSeparator+FusionChartsExportHelper.RESOURCEPATH+"validation_def.jsp";
String relativePathToValidationDef = FusionChartsExportHelper.RESOURCEPATH+"validation_def.jsp";

Share this post


Link to post
Share on other sites

Hi Aman,

There is no problem in the export code - That part of the code is not used currently - will not cause any issues.

I think the problem is with the properties file.

Can you please attach your fusioncharts_export.properties file?

Srividya

Share this post


Link to post
Share on other sites

So I changed the RESOURCEPATH of my properties file to:

 

 

 

RESOURCEPATH=/analytics/static/Fusion/FusionCharts/Resources/

 

 

 

but still the same result :)

Share this post


Link to post
Share on other sites

Hi Aman,

Please verify FusionCharts folder is within WEBAPP-ROOT> analytics > static > Fusion.

Try giving relative path to the exporter jsp. If your chart jsp is in root folder, then

exportHandler= './analytics/static/Fusion/FusionCharts/FCExporter.jsp'

would work.

Also, have you configured the logger? If so, we could see some log messages too, for further debugging.

Srividya

Share this post


Link to post
Share on other sites

Hey Srividya,

 

 

 

Sorry for bugging you so much... its so frustrating, I am so close yet so far :)

 

 

 

Did the change you mentioned, and still the same blank output.

 

 

 

Below is my resources file: I tried it with localhost and "."

 

 

 


#This constant defines the name of the export handler jsp file - DO NOT MODIFY THIS!!!

EXPORTHANDLER=FCExporter_



#Path where the export handler files are located

#Please note that the resource path should be relative to 

#FCExporter.jsp file's directory

#By default the path is "Resources/"

RESOURCEPATH=./analytics/static/Fusion/FusionCharts/Resources/



#Please specify the path to a folder with write permissions relative to web application root

#The exported image/PDF files would be saved here.

SAVEPATH=./images/



#This constant HTTP_URI stores the HTTP reference to 

#the folder where exported charts will be saved. 

#Please enter the HTTP representation of that folder 

#in this constant e.g., http://www.yourdomain.com/images/

HTTP_URI=http://www.yourdomain.com/images/





#OVERWRITEFILE sets whether the export handler would overwrite an existing file 

#the newly created exported file. If it is set to false the export handler would

#not overwrite. In this case if INTELLIGENTFILENAMING is set to true the handler

#would add a suffix to the new file name. The suffix is a randomly generated UUID.

#Additionally, you can add a timestamp or random number as additional prefix.

OVERWRITEFILE=false

INTELLIGENTFILENAMING=true

FILESUFFIXFORMAT=TIMESTAMP



Share this post


Link to post
Share on other sites

Hi Srividya,

 

 

 

I cant attach any other file now, because its complaining about the attachment size exceeded.

 

 

 

Can I have your email address so that I can forward you the webapp folder. You can email me at [email protected] and I can reply back to that :-) if thats not an issue. :)

Edited by Guest

Share this post


Link to post
Share on other sites

Ok, after taking a look at the webapp, I made some changes and sent it back.

Just for the benefit of all, I thought I should post the solution to the problem.

1. The path to the FusionCharts.js in the html containing the chart should be correct. ( This can cause the "FusionCharts undefined" javascript error. The chart itself will not be visible in this case )

2. The swf files should be latest. ( If the swf files are not latest ( version >=3.1 ) then export-related context menu items "Save As JPEG" etc will not be available. )

3. The path to the FCExporter.jsp in exportHandler XML attribute should be correct. ( If this path is incorrect, you would get a "Page not found" in Internet Browser. )

4. The path to the Resources folder in the .properties file should be correct. ( If this path is incorrect, you would see a blank page after capturing data is 100% complete )

Correcting all the above problems in the webapp solved the user's issue.

Srividya

Edited by Guest

Share this post


Link to post
Share on other sites

Hi Srividya,

 

 

 

Now it doesnt een work on FireFox... i have no clue.. what is going on :)

 

 

 

After Data Capture, I am getting FCexporter.jsp (the complete code of FCexporter.jsp in the browser body)

Share this post


Link to post
Share on other sites

Hi

This is Ravi

i also configured like above as same in prevoius posts.

in my browser it's displaying with the options like save as JPEG,save as PNG,save as PDF

if i select  any of the action among those.it's showing process bar that 100% complete

up to here working fine

but the problem is i have the export path in "fusioncharts_export.properties" as ./images folder

but after 100% completion the page is re-directing to ../jsp/FCExporter.jsp page with blank data

pls help me  regarding this...

iam using fusion charts free evaluvation version and java 1.6

Share this post


Link to post
Share on other sites

Hi Aman, Ravi

This should be a path issue only. There are only 3 important path values used for export.

1. RESOURCEPATH in fusioncharts_export.properties. ( relative to web application root )

2. SAVEPATH in fusioncharts_export.properties. ( in case of server side "save"   )

3. exportHandler attribute in xml.

Please check all three.

I will upload a sample web app in my next post.

Ravi, you can test and see if that works.

Edited by Guest

Share this post


Link to post
Share on other sites

Hello,

 

I'm new to fusioncharts and just finished testing your test app. The save method does NOT save in image or whatever folder you specify in the property file, but in the root folder of the application...

Share this post


Link to post
Share on other sites

Hi,

 

 

 

Thanks for replying to my question. Find attached the structure of the files I'm trying to adapt...

 

When I run the program no error is thrown (js alert), but a javascript error occurs..

 

 

 

Any suggestion would be great. Thanks.

 

 

 

oswald

post-7985-128441581427_thumb.jpg

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now