In this post we are sharing the code to make udf file by text file....
Write.java
package com.server;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import com.client.GreetingService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {
Connection con=null;
Statement st=null;
ResultSet rs=null;
String query;
String url="jdbc:mysql://localhost:3306/logindb";
public void call()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e)
{
System.out.print(e.getMessage());
}
try
{
con=DriverManager.getConnection(url, "root", "");
st=con.createStatement();
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
}
@Override
public String check(String name, String password) {
// TODO Auto-generated method stub
String ss="no";
call();
try
{
rs = st.executeQuery("select * from admin where name='" + name + "' and password='" + password+"'" );
if(rs.next())
{
ss="yes";
System.out.println(rs.getString("name"));
System.out.println(rs.getString("password"));
}
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
return ss;
}
@Override
public String sign(String name, String password) {
String ss="no";
int k=0;
call();
try
{
k=st.executeUpdate("insert into admin values('" + name + "','" + password+"')" );
if(k==1)
{
ss="yes";
}
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
return ss;
// TODO Auto-generated method stub
}
@SuppressWarnings("deprecation")
@Override
public String writee(String ss, String st, String sa) {
// TODO Auto-generated method stub
FileWriter ryt;
try{
System.out.println("123456789");
Date today = new Date();
// DateTimeFormat fmt = DateTimeFormat.getFormat("EEEE_MMMM_dd_yyyy");
// prints Monday, December 17, 2007 in the default locale
//GWT.log(fmt.format(today), null);
int s1=today.getDate();
int s2=today.getMonth();
int s3=today.getYear();
int s4=today.getHours();
int s5=today.getMinutes();
int s6=today.getSeconds();
File ff=new File("G://gwt-2.0.4//gwt-2.0.4//proj//war//images//"+st+sa+"_"+s1+"."+s2+"."+s3+"_"+s4+"."+s5+"."+s6+".txt");
ff.createNewFile();
ryt=new FileWriter("G://gwt-2.0.4//gwt-2.0.4//proj//war//images//"+st+sa+"_"+s1+"."+s2+"."+s3+"_"+s4+"."+s5+"."+s6+".txt");
BufferedWriter out = new BufferedWriter(ryt);
out.write(ss);
out.close();
PDFConversion pdf=new PDFConversion();
pdf.createPdf("G://gwt-2.0.4//gwt-2.0.4//proj//war//images//"+st+sa+"_"+s1+"."+s2+"."+s3+"_"+s4+"."+s5+"."+s6+".txt","G://gwt-2.0.4//gwt-2.0.4//proj//war//images//"+st+sa+"_"+s1+"."+s2+"."+s3+"_"+s4+"."+s5+"."+s6+".pdf",false);
System.out.println("12dssdsfdbvfd3456789");
}
catch(Exception e)
{
System.out.println(e+"bghh");
}
return ss;
}
}
PDFConversion.java
package com.server;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.RootPanel;
import com.gwtext.client.widgets.Window;
import com.gwtext.client.widgets.layout.FitLayout;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfWriter;
import java.io.File;
import java.io.FileOutputStream;
/**
*
* @author shunmuga
*/
public class PDFConversion
{
/**
* This method is used to convert the given file to a PDF format
* @param inputFile - Name and the path of the file
* @param outputFile - Name and the path where the PDF file to be saved
* @param isPictureFile
*/
public void createPdf(String inputFile, String outputFile, boolean isPictureFile) {
// TODO Auto-generated method stub
Rectangle pageSize = new Rectangle(2780, 2525);
Document pdfDocument = new Document(pageSize);
String pdfFilePath = outputFile;
try
{
FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath);
PdfWriter writer = null;
writer = PdfWriter.getInstance(pdfDocument, fileOutputStream);
writer.open();
pdfDocument.open();
/**
* Proceed if the file given is a picture file
*/
if (isPictureFile)
{
pdfDocument.add(com.lowagie.text.Image.getInstance(inputFile));
}
/**
* Proceed if the file given is (.txt,.html,.doc etc)
*/
else
{
File file = new File(inputFile);
pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file)));
}
RootPanel rt=RootPanel.get();
pdfDocument.close();
writer.close();
final Window window = new Window();
window.setTitle("Calculation");
window.setClosable(true);
window.setPlain(true);
window.setLayout(new FitLayout());
Frame pdfFrame = new Frame();
pdfFrame.setSize("100%", "100%");
pdfFrame.setUrl(outputFile);
window.add(pdfFrame);
window.setCloseAction(Window.CLOSE);
window.show();
rt.add(window);
}
catch (Exception exception)
{
System.out.println("Document Exception!" + exception);
}
}
}
This will make the pdf file on server side.....
Write.java
package com.server;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import com.client.GreetingService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {
Connection con=null;
Statement st=null;
ResultSet rs=null;
String query;
String url="jdbc:mysql://localhost:3306/logindb";
public void call()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e)
{
System.out.print(e.getMessage());
}
try
{
con=DriverManager.getConnection(url, "root", "");
st=con.createStatement();
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
}
@Override
public String check(String name, String password) {
// TODO Auto-generated method stub
String ss="no";
call();
try
{
rs = st.executeQuery("select * from admin where name='" + name + "' and password='" + password+"'" );
if(rs.next())
{
ss="yes";
System.out.println(rs.getString("name"));
System.out.println(rs.getString("password"));
}
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
return ss;
}
@Override
public String sign(String name, String password) {
String ss="no";
int k=0;
call();
try
{
k=st.executeUpdate("insert into admin values('" + name + "','" + password+"')" );
if(k==1)
{
ss="yes";
}
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
return ss;
// TODO Auto-generated method stub
}
@SuppressWarnings("deprecation")
@Override
public String writee(String ss, String st, String sa) {
// TODO Auto-generated method stub
FileWriter ryt;
try{
System.out.println("123456789");
Date today = new Date();
// DateTimeFormat fmt = DateTimeFormat.getFormat("EEEE_MMMM_dd_yyyy");
// prints Monday, December 17, 2007 in the default locale
//GWT.log(fmt.format(today), null);
int s1=today.getDate();
int s2=today.getMonth();
int s3=today.getYear();
int s4=today.getHours();
int s5=today.getMinutes();
int s6=today.getSeconds();
File ff=new File("G://gwt-2.0.4//gwt-2.0.4//proj//war//images//"+st+sa+"_"+s1+"."+s2+"."+s3+"_"+s4+"."+s5+"."+s6+".txt");
ff.createNewFile();
ryt=new FileWriter("G://gwt-2.0.4//gwt-2.0.4//proj//war//images//"+st+sa+"_"+s1+"."+s2+"."+s3+"_"+s4+"."+s5+"."+s6+".txt");
BufferedWriter out = new BufferedWriter(ryt);
out.write(ss);
out.close();
PDFConversion pdf=new PDFConversion();
pdf.createPdf("G://gwt-2.0.4//gwt-2.0.4//proj//war//images//"+st+sa+"_"+s1+"."+s2+"."+s3+"_"+s4+"."+s5+"."+s6+".txt","G://gwt-2.0.4//gwt-2.0.4//proj//war//images//"+st+sa+"_"+s1+"."+s2+"."+s3+"_"+s4+"."+s5+"."+s6+".pdf",false);
System.out.println("12dssdsfdbvfd3456789");
}
catch(Exception e)
{
System.out.println(e+"bghh");
}
return ss;
}
}
package com.server;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.RootPanel;
import com.gwtext.client.widgets.Window;
import com.gwtext.client.widgets.layout.FitLayout;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfWriter;
import java.io.File;
import java.io.FileOutputStream;
/**
*
* @author shunmuga
*/
public class PDFConversion
{
/**
* This method is used to convert the given file to a PDF format
* @param inputFile - Name and the path of the file
* @param outputFile - Name and the path where the PDF file to be saved
* @param isPictureFile
*/
public void createPdf(String inputFile, String outputFile, boolean isPictureFile) {
// TODO Auto-generated method stub
Rectangle pageSize = new Rectangle(2780, 2525);
Document pdfDocument = new Document(pageSize);
String pdfFilePath = outputFile;
try
{
FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath);
PdfWriter writer = null;
writer = PdfWriter.getInstance(pdfDocument, fileOutputStream);
writer.open();
pdfDocument.open();
/**
* Proceed if the file given is a picture file
*/
if (isPictureFile)
{
pdfDocument.add(com.lowagie.text.Image.getInstance(inputFile));
}
/**
* Proceed if the file given is (.txt,.html,.doc etc)
*/
else
{
File file = new File(inputFile);
pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file)));
}
RootPanel rt=RootPanel.get();
pdfDocument.close();
writer.close();
final Window window = new Window();
window.setTitle("Calculation");
window.setClosable(true);
window.setPlain(true);
window.setLayout(new FitLayout());
Frame pdfFrame = new Frame();
pdfFrame.setSize("100%", "100%");
pdfFrame.setUrl(outputFile);
window.add(pdfFrame);
window.setCloseAction(Window.CLOSE);
window.show();
rt.add(window);
}
catch (Exception exception)
{
System.out.println("Document Exception!" + exception);
}
}
}
This will make the pdf file on server side.....
0 Response to "Converting or creating pdf file from richtexteditor to textfile"
Post a Comment