[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.3

Jpeg to pdf conversion in Java

Asked by aman0711 in Java Server Pages (JSP)

Tags: jsp, jpeg, pdf

Hi experts,
                  I am trying to display a flash image on my jsp pages. i want to save the same image as a pdf format. is it possible to that? Right now I am using a short code for saving the same chart as a jpeg file.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
<%@ page import="java.io.OutputStream"%>
<%@ page import="java.awt.Color"%>
<%@ page import="java.awt.Graphics"%>
<%@ page import="java.awt.image.BufferedImage"%>
<%@ page import="javax.imageio.ImageIO"%>
<%
	//Decoded data from charts.
	String data="";
	//Rows of color values.
	String[] rows;
	//Width and height of chart.
	int width=0;
	int height=0;
	//Default background color of the chart
	String bgcolor="";
	Color bgColor;
 
	//Get the width and height from form
	try{
		width = Integer.parseInt(request.getParameter("width"));
		height = Integer.parseInt(request.getParameter("height"));	
	}
	catch(Exception e){
		//If the width and height have not been given, we cannot create the image.
		out.print("Image width/height not provided.");
		out.close();
	}
 
	if(width==0 || height==0){
		//If the width and height are less than 1, we cannot create the image.
		out.print("Image width/height not provided.");
		out.close();
	}
		
	//Get background color from request and set default
	bgcolor =request.getParameter("bgcolor");
	if (bgcolor==null || bgcolor=="" || bgcolor==null){
			bgcolor = "FFFFFF";
	}
	//Convert background color to color object	
	bgColor = new Color(Integer.parseInt(bgcolor,16));
 
	//Get image data  from request
	data = request.getParameter("data");
 
	if(data==null){
		//If image data not provided.
		out.print("Image Data not supplied.");
		out.close();
	}
 
	try{
		//Parse data 
		rows = new String[height+1];
		rows = data.split(";");
			
		//Bitmap to store the chart.
		//Reference to graphics object - gr
		BufferedImage chart = new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);
		Graphics gr = chart.createGraphics();
		gr.setColor(bgColor);
		gr.fillRect(0,0,width,height);	
	
		String c;
		int r;
		int ri = 0;
		for (int i=0; i<rows.length; i++){
			//Split individual pixels.			
			String[] pixels = rows[i].split(",");			
			//Set horizontal row index to 0
			ri = 0;
			for (int j=0; j<pixels.length; j++){				
				//Now, if it's not empty, we process it				
				//Split the color and repeat factor
	
				String[] clrs = pixels[j].split("_");	
				//Reference to color
				c = clrs[0];
				r = Integer.parseInt(clrs[1]);
	
				//If color is not empty (i.e. not background pixel)
				if (c!=null && c.length()>0 && c!=""){		
					if (c.length()<6){
						//If the hexadecimal code is less than 6 characters, pad with 0
						StringBuffer str = new StringBuffer(c);
						int strLength  = str.length();
						  for ( int p = c.length()+1; p <= 6 ; p ++ ) {
								  str.insert( 0, "0" );
						  }
						//Assing the new padded string
						c = str.toString();
					}
					for (int k=1; k<=r; k++){	
						//Draw each pixel
						gr.setColor(new Color(Integer.parseInt(c,16)));
						gr.fillRect(ri, i,1,1);
						//Increment horizontal row count
						ri++;						
					}
				}else{
					//Just increment horizontal index
					ri = ri + r;
				}
			}
		}
		
	
		//Returns the image
		response.setContentType("image/jpeg");
		response.addHeader("Content-Disposition", "attachment; filename=\"FusionCharts.jpg\"");
		OutputStream os = response.getOutputStream();
		ImageIO.write(chart, "jpeg", os);
		os.close();
		
	}catch(Exception e){
		//IF the image data is mal-formatted.
		out.print("Image data is not in proper format.");
		out.close();
	}
%>
[+][-]01/31/09 09:51 PM, ID: 23520194Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Java Server Pages (JSP)
Tags: jsp, jpeg, pdf
Sign Up Now!
Solution Provided By: bluebelldiscovery
Participating Experts: 2
Solution Grade: B
 
[+][-]01/29/09 10:29 AM, ID: 23500739Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/29/09 10:39 AM, ID: 23500834Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/29/09 10:42 AM, ID: 23500861Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/29/09 10:46 AM, ID: 23500897Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/29/09 10:49 AM, ID: 23500928Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/29/09 10:51 AM, ID: 23500954Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/29/09 10:54 AM, ID: 23500989Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/29/09 10:55 AM, ID: 23501003Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/29/09 10:56 AM, ID: 23501017Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]01/29/09 12:17 PM, ID: 23502003Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/29/09 12:45 PM, ID: 23502297Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/29/09 12:50 PM, ID: 23502360Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/29/09 12:57 PM, ID: 23502436Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/29/09 12:58 PM, ID: 23502454Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/31/09 09:53 PM, ID: 23520200Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625