Following code just work fine there is no error in it but not work as required..
problem 1: I want to download pdf file and redirect to home page(url:../).when ever i nevigate to url(../admin/generate_pdf)
problem 2:when ever i uncomment the commented line in Pdfdemo.java it gives me an error 404 page not found.
Pdfdemo.java
public class Pdfdemos {
private static String USER_PASSWORD = "password";
private static String OWNER_PASSWORD = "lokesh";
public String generate_pdf() {
try {
String file_name="d:\\sanjeet7.pdf";
Document document= new Document();
PdfWriter writer=PdfWriter.getInstance(document, new FileOutputStream(file_name));
// writer.setEncryption(USER_PASSWORD.getBytes(),
// OWNER_PASSWORD.getBytes(), PdfWriter.ALLOW_PRINTING |PdfWriter.ALLOW_ASSEMBLY|
// PdfWriter.ALLOW_COPY|
// PdfWriter.ALLOW_DEGRADED_PRINTING|
// PdfWriter.ALLOW_FILL_IN|
// PdfWriter.ALLOW_MODIFY_ANNOTATIONS|
// PdfWriter.ALLOW_MODIFY_CONTENTS|
// PdfWriter.ALLOW_SCREENREADERS|
// PdfWriter.ALLOW_ASSEMBLY|
// PdfWriter.ENCRYPTION_AES_128, 0);
document.open();
document.add(new Paragraph(" "));document.add(new Paragraph(" "));
String days_in_week[]= {"monday","tuesday","webnesday","thursday","friday","saturday"};
int period=8;
String user="springstudent";
String pass="springstudent";
String jdbcUrl="jdbc:mysql://localhost:3306/web_customer_tracker?useSSL=false";
String driver="com.mysql.jdbc.Driver";
Connection myconn=DriverManager.getConnection(jdbcUrl,user,pass);
PreparedStatement ps=null;
ResultSet rs=null;
String query="select * from class_t";
ps=myconn.prepareStatement(query);
rs=ps.executeQuery();
while(rs.next()) {
Paragraph para=new Paragraph("Time table for class"+rs.getString("class")+rs.getString("section"));
document.add(para);
System.out.println(rs.getInt("id"));
PdfPTable table=new PdfPTable(period+1);
for(int i=0;i<days_in_week.length;i++) {
for(int j=0;j<period+1;j++) {
if(j==5) {
table.addCell("recess");
}else {
table.addCell("this is "+j);
}
}
}
document.add(table);
document.newPage();
}
document.close();
System.out.println("finish");
return file_name;
}catch(Exception e) {
System.out.println(e);
}
return null;
}
}
Generate_pdf_controller.java
@Controller
@RequestMapping("/admin/generate_pdf")
public class Generate_pdf_Controller {
@GetMapping("/online")
public String generating_pdf(Model theModel) {
System.out.println("hello");
CustomerServiceImpl pal=new CustomerServiceImpl();
Pdfdemos pal1=new Pdfdemos();
String xx=pal1.generate_pdf();
return "redirect:/";
}
}