How to Display an Image in PDF, which is retrieved from MySql Database :JSP and iText -


i have stored image in mediumblob in mysql. want retrieve image , put in itext pdf.

i have manange work out blob datatype. doesnt work medium blob.

after have retrieved image , stored in blob datatype. after tried convert bytes.

    httpsession session=request.getsession();     string name="";     string birthdate="";     string address="";     string gender="";     string doctor="";     string disease="";     string pregnant="";     string nursing="";     string pan="";     string smoking="";     string allergies="";     string medicines="";     string treatment="";         string email=session.getattribute("email").tostring();         session.setattribute("email",email);     blob image0 = null;         blob image1 = null;         blob image2 = null;         blob image3 = null;         blob image4 = null;          byte[] imagebytes = null;         byte[] imagebytes1= null;         byte[] imagebytes2= null;         byte[] imagebytes3= null;         byte[] imagebytes4= null;      try     {          class.forname("com.mysql.jdbc.driver");         connection con = drivermanager.getconnection("jdbc:mysql://localhost:3306/dentistree","root", "tiger");         statement st = con.createstatement();         statement st1 = con.createstatement();         statement st2=con.createstatement();          resultset rs;         resultset rs1;         resultset rs2;          string query="select * patient email='"+email+"'";         string query1="select * casehistory email='"+email+"'";         string query2="select * sessionmedia email='"+email+"'";          rs=st.executequery(query);         rs1=st1.executequery(query1);         rs2=st2.executequery(query2);         while(rs.next())         {             name=rs.getstring(1);             birthdate=rs.getstring(3);             address=rs.getstring(4);             gender=rs.getstring(6);         }         while(rs1.next())         {             doctor=rs1.getstring(2);             disease=rs1.getstring(3);             pregnant=rs1.getstring(4);             nursing=rs1.getstring(5);             pan=rs1.getstring(6);             smoking=rs1.getstring(7);             allergies=rs1.getstring(8);             medicines=rs1.getstring(9);             treatment=rs1.getstring(10);               if(pregnant.equals("nopreg"))             {                 pregnant="no";             }             else             {                 pregnant="yes";             }             if(nursing.equals("nonuture"))             {                 nursing="no";             }             else             {                 nursing="yes";             }             if(pan.equals("nopan"))             {                 pan="no";             }             else             {                 pan="yes";             }             if(smoking.equals("yessmoke"))             {                 smoking="yes";             }             else             {                 smoking="no";             }          }         while(rs2.next())         {             image0= rs.getblob(3);             image1= rs.getblob(4);             image2= rs.getblob(5);             image3= rs.getblob(6);             image4= rs.getblob(7);          }         imagebytes = image0.getbytes(1, (int) image0.length());         image image00=image.getinstance(imagebytes);         image00.scaleabsolute(300,300);          document document = new document();          pdfwriter.getinstance(document, response.getoutputstream());         image image = image.getinstance("c:\\users\\abhishek\\desktop\\capture.png");          document.open();          document.add(image);         document.add(new paragraph("doctor name:    dr.seema maurya"));         document.add(chunk.newline );         document.add(new paragraph("name:"+"            "+name));         document.add(new paragraph(""));         document.add(new paragraph(""));         document.add(new paragraph("date of birth:"+"  "+birthdate));         document.add(new paragraph(""));         document.add(new paragraph(""));         document.add(new paragraph("address:"+"         "+address));         document.add(new paragraph(""));         document.add(new paragraph(""));         document.add(new paragraph("email-id:"+"        "+email));         document.add(new paragraph(""));         document.add(new paragraph(""));         document.add(new paragraph("gender:"+"          "+gender));         document.add(new paragraph(""));         document.add(new paragraph(""));         document.add(chunk.newline );         document.add(new paragraph("diseases:"+"        "+disease));         document.add(new paragraph(""));         document.add(new paragraph(""));         document.add(chunk.newline );         document.add(new paragraph("pregnant:"+"        "+pregnant));         document.add(new paragraph(""));         document.add(new paragraph(""));         document.add(new paragraph("nursing:"+"          "+nursing));         document.add(new paragraph(""));         document.add(new paragraph(""));         document.add(new paragraph("pan-chewing:"+""+pan));         document.add(new paragraph(""));         document.add(new paragraph(""));         document.add(new paragraph("smoking:"+"         "+smoking));         document.add(new paragraph(""));         document.add(new paragraph(""));         document.add(new paragraph("medicines:"+"       "+medicines));         document.add(new paragraph(""));         document.add(new paragraph(""));         document.add(chunk.newline );         document.add(new paragraph("allergies:"+"       "+allergies));         document.add(chunk.newline );         document.add(new paragraph("session images:"));         document.add(chunk.newline );         document.add(image00);         document.add(chunk.newline );            document.close();     }      catch (documentexception de) {         throw new ioexception(de.getmessage());     }     catch(exception e)     {      } } } 


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -