`
songsong_b
  • 浏览: 69722 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论
阅读更多
package com.embraiz.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.PageSize;
import com.lowagie.text.Rectangle;



import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Font;
import com.embraiz.common.sql.SQLBridge;


import com.embraiz.bo.bd.*;


public class bdApprovalPDF extends HttpServlet {

/**
* Constructor of the object.
*/
private SQLBridge sqlBridge;
public bdApprovalPDF() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) {

  
    
try
{
sqlBridge = new SQLBridge();
sqlBridge.setConnectionName("proxool.erppool");
sqlBridge.setConnectionSwitch("on");




String boId=request.getParameter("id");

     if(boId==null || boId.trim().equals("")) boId="0";
     BdApproval bdApp=new BdApproval();
    
     bdApp.setFormId(new Integer(boId));
     bdApp.getById(sqlBridge);
     bdApp.getCategoryByContactPerson(sqlBridge, bdApp.getContactPerson());
     BdApprovalDetail tempBdDetail = new BdApprovalDetail();
tempBdDetail.setForm_id(Integer.valueOf(boId));
List<BdApprovalDetail> detList = tempBdDetail.list(sqlBridge);
   
    
    
Rectangle rectPageSize = new Rectangle(PageSize.A4);
rectPageSize = rectPageSize.rotate();
Document document = new Document(rectPageSize,10,10,50,10);
float width = document.getPageSize().getWidth();
float height = document.getPageSize().getHeight();

response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename=\"bdApproval.pdf\"");
         PdfWriter.getInstance(document, response.getOutputStream());
       
         //BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        BaseFont bfChinese = BaseFont.createFont("MSung-Light", "UniCNS-UCS2-H", false);
Font FontChinese8 = new Font(bfChinese, 12, Font.BOLD);//, Font.UNDERLINE);
Font FontEnglish8 = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
Font FontChinese20 = FontFactory.getFont(FontFactory.HELVETICA, 20, Font.BOLD);
 


document.open();
float[] columnDefinitionSize = { 25.00F, 25.00F, 16.66F,33.34F };
PdfPTable tableTop = new PdfPTable(1);
PdfPTable table = null;
PdfPCell cell=new PdfPCell(new Paragraph("",FontChinese8));
cell.setBorderWidthLeft(0);
cell.setBorderWidthRight(0);
cell.setBorderWidthTop(0);
cell.setBorderWidthBottom(1);
cell.setPaddingTop(5);
cell.setFixedHeight(20);

tableTop.setTotalWidth(width - 50);
tableTop.setLockedWidth(true);


table = new PdfPTable(columnDefinitionSize);
table.getDefaultCell().setBorder(0);

table.addCell(new Paragraph("BD Approval Form",FontChinese20));
table.addCell(new Paragraph(" "));
table.addCell(new Paragraph("Issue Date:",FontEnglish8));
cell.setPhrase(new Paragraph(bdApp.getIssueDate().toString().substring(0, 10),FontChinese8));
table.addCell(cell);

table.addCell(new Paragraph(" "));
table.addCell(new Paragraph(" "));
table.addCell(new Paragraph("Sales Person:",FontEnglish8));
cell.setPhrase(new Paragraph(bdApp.getOwnUserName(),FontChinese8));
table.addCell(cell);

table.addCell(new Paragraph("Booking Order NO.:",FontEnglish8));
table.addCell(new Paragraph(bdApp.getBoNumber()));
table.addCell(new Paragraph(" "));
table.addCell(new Paragraph(" "));

tableTop.addCell(table);
document.add(tableTop);

PdfPTable tableMid = new PdfPTable(1);
tableMid.setTotalWidth(width - 50);
tableMid.setLockedWidth(true);

PdfPTable tableMidContentAll = new PdfPTable(1);
tableMidContentAll.getDefaultCell().setBorder(0);

PdfPTable table2 = null;
float[] columnDefinitionSizeMid = { 16.66F, 33.34F, 16.66F,33.34F };
table2 = new PdfPTable(columnDefinitionSizeMid);
table2.getDefaultCell().setBorder(0);


table2.addCell(new Paragraph(""));
table2.addCell(new Paragraph(""));
table2.addCell(new Paragraph("Product:",FontEnglish8));
cell.setPhrase(new Paragraph(bdApp.getProduct(),FontChinese8));
table2.addCell(cell);
table2.addCell(new Paragraph("Company Name:",FontEnglish8));
cell.setPhrase(new Paragraph(bdApp.getCompanyName(),FontChinese8));
table2.addCell(cell);
table2.addCell(new Paragraph("Category:",FontEnglish8));
cell.setPhrase(new Paragraph(bdApp.getCategory(),FontChinese8));
table2.addCell(cell);
table2.addCell(new Paragraph("Contact Person:",FontEnglish8));
cell.setPhrase(new Paragraph(bdApp.getContactPerson(),FontChinese8));
table2.addCell(cell);
table2.addCell(new Paragraph("Title:",FontEnglish8));
cell.setPhrase(new Paragraph(bdApp.getTitle(),FontChinese8));
table2.addCell(cell);

tableMidContentAll.addCell(table2);

float[] columnDefinitionSizeMid21 = { 16.66F, 14.50F,4.34F,14.50F, 16.66F,33.34F };
PdfPTable table21 = null;
table21 = new PdfPTable(columnDefinitionSizeMid21);
table21.getDefaultCell().setBorder(0);



table21.addCell(new Paragraph("Tel No. :    (D)",FontEnglish8));
cell.setPhrase(new Paragraph(bdApp.getTelNumberDirect(),FontChinese8));
table21.addCell(cell);
table21.addCell(new Paragraph("(G)",FontEnglish8));
cell.setPhrase(new Paragraph(bdApp.getTelNumberGeneral(),FontChinese8));
table21.addCell(cell);
table21.addCell(new Paragraph("Fax No.:",FontEnglish8));
cell.setPhrase(new Paragraph(bdApp.getFoxNumber(),FontChinese8));
table21.addCell(cell);

float[] columnDefinitionSizeMid22 = { 16.66F, 83.34F};
PdfPTable table22 = null;
table22 = new PdfPTable(columnDefinitionSizeMid22);
table22.getDefaultCell().setBorder(0);

tableMidContentAll.addCell(table21);

table22.addCell(new Paragraph("Adress:",FontEnglish8));
cell.setPhrase(new Paragraph(bdApp.getAddress(),FontChinese8));
table22.addCell(cell);

tableMidContentAll.addCell(table22);

tableMid.addCell(tableMidContentAll);

document.add(tableMid);
for(int i=0;i<detList.size();i++){   ////////////for start
if(i>0){
document.newPage();
document.add(tableTop);
document.add(tableMid);
}
BdApprovalDetail tempD=detList.get(i);

PdfPTable tableBottom = new PdfPTable(1);
tableBottom.setTotalWidth(width - 50);
tableBottom.setLockedWidth(true);

PdfPTable tableBottomContentAll = new PdfPTable(1);
tableBottomContentAll.getDefaultCell().setBorder(0);

PdfPTable table3 = null;
float[] columnDefinitionSizeBottom = { 16.66F, 33.34F, 16.66F,33.34F };
table3 = new PdfPTable(columnDefinitionSizeBottom);
table3.getDefaultCell().setBorder(0);

//Font FontEnglish8UnderLine = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD);
table3.addCell(new Paragraph(""));
PdfPCell cell2=new PdfPCell(new Paragraph("MEDIA RENTAL",FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE|Font.BOLD)));
cell2.setHorizontalAlignment((Element.ALIGN_CENTER));
cell2.setBorder(0);
table3.addCell(cell2);
table3.addCell(new Paragraph(""));
cell2=new PdfPCell(new Paragraph("Production & Installation",FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE|Font.BOLD)));
cell2.setHorizontalAlignment((Element.ALIGN_CENTER));
cell2.setBorder(0);
table3.addCell(cell2);
table3.addCell(new Paragraph("Rental Contract No:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getContractNo()==null?"":tempD.getContractNo(),FontChinese8));
table3.addCell(cell);
table3.addCell(new Paragraph("P & I Contract No:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getPIContratNo()==null?"":tempD.getPIContratNo(),FontChinese8));
table3.addCell(cell);
table3.addCell(new Paragraph("Site Name & No:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getSiteName(),FontChinese8));
table3.addCell(cell);
table3.addCell(new Paragraph("P & I Cost:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getPICost().toString(),FontChinese8));
table3.addCell(cell);
tableBottomContentAll.addCell(table3);

PdfPTable table31 = new PdfPTable(columnDefinitionSizeMid21);
table31.getDefaultCell().setBorder(0);
table31.addCell(new Paragraph("Display Period:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getDisplayFrom()==null?"":tempD.getDisplayFrom().toString(),FontChinese8));
table31.addCell(cell);
table31.addCell(new Paragraph(" to ",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getDisplayTo()==null?"":tempD.getDisplayTo().toString(),FontChinese8));
table31.addCell(cell);
table31.addCell(new Paragraph("Installation Date:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getInstallationDate()==null?"":tempD.getInstallationDate().toString(),FontChinese8));
table31.addCell(cell);
tableBottomContentAll.addCell(table31);

float[] columnDefinitionSizeMid32 = { 16.66F, 18.84F,14.50F, 16.66F,33.34F };
PdfPTable table32 = new PdfPTable(columnDefinitionSizeMid32);
table32.getDefaultCell().setBorder(0);
String durationTime="";
if(tempD.getDurationUnit()!=null&&tempD.getDurationUnit().equals("d")){
durationTime="day(s)";
}else if(tempD.getDurationUnit()!=null&&tempD.getDurationUnit().equals("m")){
durationTime="month(s)";
}else if(tempD.getDurationUnit()!=null&&tempD.getDurationUnit().equals("y")){
durationTime="year(s)";
}
table32.addCell(new Paragraph("Duraction:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getDuration()==null?"":tempD.getDuration().toString(),FontChinese8));
table32.addCell(cell);
table32.addCell(new Paragraph(durationTime,FontEnglish8));
table32.addCell(new Paragraph("Payment Term:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getPaymentTermRental()==null?"":tempD.getPaymentTermRental(),FontChinese8));
table32.addCell(cell);
table32.addCell(new Paragraph("Rate Card:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getRateCard()==null?"":tempD.getRateCard().toString(),FontChinese8));
table32.addCell(cell);
table32.addCell(new Paragraph("month(s)",FontEnglish8));
table32.addCell(new Paragraph("Discount(if any):",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getRemarkRental()==null?"":tempD.getRemarkRental(),FontChinese8));
table32.addCell(cell);
table32.addCell(new Paragraph("Discount%:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getDiscount()==null?"":tempD.getDiscount().toString(),FontChinese8));
table32.addCell(cell);
table32.addCell(new Paragraph(""));
table32.addCell(new Paragraph(""));
cell.setPhrase(new Paragraph("",FontChinese8));
table32.addCell(cell);
table32.addCell(new Paragraph("Net Rate:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getNetRate()==null?"":tempD.getNetRate().toString(),FontChinese8));
table32.addCell(cell);
table32.addCell(new Paragraph("month(s)",FontEnglish8));
table32.addCell(new Paragraph("",FontEnglish8));
cell.setPhrase(new Paragraph("",FontChinese8));
table32.addCell(cell);
tableBottomContentAll.addCell(table32);

PdfPTable table33 = null;
table33 = new PdfPTable(columnDefinitionSizeBottom);
table33.getDefaultCell().setBorder(0);
table33.addCell(new Paragraph("No.of Spots per hour:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getSportsPerHour()==null?"":tempD.getSportsPerHour().toString(),FontChinese8));
table33.addCell(cell);
table33.addCell(new Paragraph(""));
cell.setPhrase(new Paragraph("",FontChinese8));
table33.addCell(cell);
table33.addCell(new Paragraph("Duration of Spot:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getDurationSpot()==null?"":tempD.getDurationSpot().toString(),FontChinese8));
table33.addCell(cell);
table33.addCell(new Paragraph(""));
cell.setPhrase(new Paragraph("",FontChinese8));
table33.addCell(cell);
table33.addCell(new Paragraph("payment Term:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getPaymentTermProduction()==null?"":tempD.getPaymentTermProduction(),FontChinese8));
table33.addCell(cell);
table33.addCell(new Paragraph(""));
cell.setPhrase(new Paragraph("",FontChinese8));
table33.addCell(cell);
table33.addCell(new Paragraph("Total Rental:",FontEnglish8));
cell.setPhrase(new Paragraph(bdApp.getTotalRentalSum().toString(),FontChinese8));
table33.addCell(cell);
table33.addCell(new Paragraph(""));
table33.addCell(new Paragraph(""));
table33.addCell(cell);
tableBottomContentAll.addCell(table33);

PdfPTable table34 = null;
table34 = new PdfPTable(columnDefinitionSizeMid22);
table34.getDefaultCell().setBorder(0);
table34.addCell(new Paragraph("Remarks:",FontEnglish8));
cell.setPhrase(new Paragraph(tempD.getRemarkProduction()==null?"":tempD.getRemarkProduction(),FontChinese8));
table34.addCell(cell);
tableBottomContentAll.addCell(table34);

// PdfPTable table35 = null;
// table35 = new PdfPTable(columnDefinitionSizeBottom);
// table35.getDefaultCell().setBorder(0);
// table35.addCell(new Paragraph("Sales Head Approval:",FontEnglish8));
// cell.setPhrase(new Paragraph("",FontChinese8));
// table35.addCell(cell);
// table35.addCell(new Paragraph("BD Approval",FontEnglish8));
// cell.setPhrase(new Paragraph("",FontChinese8));
// table35.addCell(cell);
// tableBottomContentAll.addCell(table35);

tableBottom.addCell(tableBottomContentAll);
document.add(tableBottom);

PdfPTable pageTble =new PdfPTable(1);
pageTble.getDefaultCell().setBorder(0);
PdfPCell cell5=new PdfPCell(new Paragraph("Page "+(i+1),FontFactory.getFont(FontFactory.HELVETICA, 12)));
cell5.setPaddingTop(20);
cell5.setHorizontalAlignment((Element.ALIGN_CENTER));
cell5.setBorder(0);
pageTble.addCell(cell5);
document.add(pageTble);
}/////////end for

document.close();
}catch(Exception e)
{

}finally
{
try {
sqlBridge.setConnectionSwitch("off");
} catch (Exception e) {
e.printStackTrace();
}
}


// step 5: we close the document

}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println("  <BODY>");
out.print("    This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println("  </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics