您的位置:首页 > 其它

打印PDF报错:STSong-Light' with 'UniGB-UCS2-H' is not recognized

2017-12-20 18:25 676 查看
在做打印pdf功能时 出现:STSong-Light' with 'UniGB-UCS2-H' is not recognized 的问题,项目用的是maven,经过查找百度最终解决了,

原理还不能用文字说明,下次补上

之前做打印用的包是:iimport com.lowagie.*;

<dependency>

<groupId>com.lowagie</groupId>

<artifactId>itext</artifactId>

<version>2.1.7</version>

</dependency>

由于报错,修改版本改为引用

<dependency>

<groupId>com.lowagie</groupId>

<artifactId>itext</artifactId>

<version>4.2.2</version>

</dependency>

但修改版本后报错,这是itext4.2.2版本内引用的itextpdf,

后来增加itext-asian后不报错

<dependency>

<groupId>com.itextpdf</groupId>

<artifactId>itext-asian</artifactId>

<version>5.2.0</version>

</dependency>

修改后代码:

import java.text.NumberFormat;

import java.util.ArrayList;

import java.util.Date;

import java.util.List;

import java.util.Locale;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;

import org.springframework.web.servlet.ModelAndView;

import com.itextpdf.text.Document;

import com.itextpdf.text.Element;

import com.itextpdf.text.Font;

import com.itextpdf.text.Image;

import com.itextpdf.text.PageSize;

import com.itextpdf.text.Paragraph;

import com.itextpdf.text.Rectangle;

import com.itextpdf.text.pdf.BaseFont;

import com.itextpdf.text.pdf.PdfPCell;

import com.itextpdf.text.pdf.PdfPTable;

import com.itextpdf.text.pdf.PdfWriter;

/**

* AuditProductSalesOrderController Controller

* @author xq

* @date 2017-02-10

*/

public class AuditFinanceController extends BizMultiActionController{

/**

* 方法说明:打印付款单

*/

public ModelAndView printPaymentApplication(HttpServletRequest request, HttpServletResponse response) throws Throwable {

/** 操作输出打印 **/

BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

Font font2 = new Font(baseFont,12,Font.NORMAL);

Font font3 = new Font(baseFont,11,Font.NORMAL);

Rectangle pageSize = PageSize.A4;

Document document = new Document(pageSize,10f,10,10,10);

response.setCharacterEncoding("UTF-8");

response.setContentType("application/pdf");

String saveFileName = "财务付款单.pdf";

response.setHeader("Content-Disposition", "inline; filename=" + ITextPDFUtil.encodeChineseDownloadFileName(request, saveFileName));

PdfWriter.getInstance(document, response.getOutputStream());

document.open();

/* String logoName = "BOLONI_LOGO.JPG";

Image logo = Image.getInstance(super.getSession().getServletContext().getRealPath("images/"+logoName));

document.add(logo);*/

Paragraph titleP = new Paragraph("财务付款单",ITextPDFUtil.getTitleFont());

titleP.setAlignment(Element.ALIGN_CENTER);

document.add(titleP);

PdfPTable table = new PdfPTable(9);

table.setWidthPercentage(100);

table.setWidths(new int[]{2,4,2,4,4,3,3,4,5});

table.setSpacingAfter(4);

PdfPCell cell = null;

cell = ITextPDFUtil.getCell("打印日期 : "+DateUtil.getTimeByFromat(new Date(), DateUtil.TIME_FORMAT_SEPERATE)+"",font3);

cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

cell.setColspan(9);

cell.setRowspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("订单编号",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(1);

table.addCell(cell);

cell = ITextPDFUtil.getCell(item.getOrderCode(),font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("订单阶段",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(1);

table.addCell(cell);

cell = ITextPDFUtil.getCell(stageCodeName,font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("订单性质",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(1);

table.addCell(cell);

cell = ITextPDFUtil.getCell(ProductOrderNature.getDescByCode(item.getProductOrderType()),font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("企业客户",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(1);

table.addCell(cell);

cell = ITextPDFUtil.getCell(item.getEnterpriseName(),font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("客户姓名",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(1);

table.addCell(cell);

cell = ITextPDFUtil.getCell(item.getCustomerName(),font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("客户电话",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(1);

table.addCell(cell);

cell = ITextPDFUtil.getCell(item.getMobile(),font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("订单金额",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(1);

table.addCell(cell);

NumberFormat usFormat =NumberFormat.getInstance(Locale.US);

cell = ITextPDFUtil.getCell(usFormat.format(item.getFinalSupplyPrice())+"",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("收款金额",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(1);

table.addCell(cell);

cell = ITextPDFUtil.getCell(usFormat.format(item.getEnterprisePaymentAmount())+"("+ item.getEnterprisePaymentStatus()+")",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(3);

table.addCell(cell);

cell = ITextPDFUtil.getCell("***********************************************",font3);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setColspan(9);

table.addCell(cell);

//NO 供货商
采购单 金额
采购单状态 是否付款
付款时间 采购单类型

cell = ITextPDFUtil.getCell("NO",font3);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

table.addCell(cell);

cell = ITextPDFUtil.getCell("供货商",font3);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

table.addCell(cell);

cell = ITextPDFUtil.getCell("采购单",font3);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setColspan(3);

table.addCell(cell);

cell = ITextPDFUtil.getCell("金额",font3);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

table.addCell(cell);

cell = ITextPDFUtil.getCell("付款时间",font3);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setColspan(1);

table.addCell(cell);

cell = ITextPDFUtil.getCell("采购单状态",font3);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

table.addCell(cell);

cell = ITextPDFUtil.getCell("采购单类型",font3);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

table.addCell(cell);

for(int i = 0; i < result.size(); i ++) {

ProductPurchaseOrderDTO dto = result.get(i);

cell = ITextPDFUtil.getCell((i+1)+"",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell(dto.getSupplierName(),font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell(dto.getPurchaseOrderCode(),font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(3);

table.addCell(cell);

cell = ITextPDFUtil.getCell(usFormat.format(dto.getPaymentAmount()),font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

if(Whether.Yes.getCode() == dto.getWhetherToPay()) {

cell = ITextPDFUtil.getCell(DateUtil.getTimeByFromat(dto.getPaymentTime(), DateUtil.TIME_FORMAT_SEPERATE)+"",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(1);

table.addCell(cell);

} else {

cell = ITextPDFUtil.getCell("未付款",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(1);

table.addCell(cell);

}

cell = ITextPDFUtil.getCell(dto.getOrderStatusDesc(),font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell(dto.getInventorySupplyDesc(),font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

}

document.add(table);

document.close();

return null;

}

}

修改前代码:

import java.io.IOException;

import java.text.NumberFormat;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Date;

import java.util.HashMap;

import java.util.List;

import java.util.Locale;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;

import org.apache.poi.hssf.usermodel.HSSFFont;

import org.apache.poi.hssf.usermodel.HSSFSheet;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.apache.poi.hssf.util.HSSFColor;

import com.lowagie.text.Cell;

import com.lowagie.text.Document;

import com.lowagie.text.DocumentException;

import com.lowagie.text.Element;

import com.lowagie.text.Font;

import com.lowagie.text.Image;

import com.lowagie.text.PageSize;

import com.lowagie.text.Paragraph;

import com.lowagie.text.Rectangle;

import com.lowagie.text.Table;

import com.lowagie.text.pdf.BaseFont;

import com.lowagie.text.pdf.PdfWriter;

public class MainMaterialSettlementAccountAction extends BaseAction{

@Note("打印账务付款通知书")

public String printMainMaterialSettlementOrder4Payment() throws Exception{

Long [] pids = ClassTypeParse.toLongs(StringUtil.splitStr(super.getStr("pids"),","));

BaseFont baseFont=baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

Long supplierID = null;

double settlementAmount = 0;

List<String> sttlementAccontCodes = new ArrayList<String>();

Font font3=new Font(baseFont,11,Font.BOLD);

Rectangle pageSize = PageSize.A4;

Document document = new Document(pageSize,10f,10,10,10);

HttpServletResponse response = super.getResponse();

response.setCharacterEncoding("UTF-8");

response.setContentType("application/pdf");

String saveFileName = "财务付款通知书";

response.setHeader("Content-Disposition", "inline; filename="

+PersistUtil.encodeChineseDownloadFileName(super.getRequest(), saveFileName+".pdf"));

PdfWriter.getInstance(document, response.getOutputStream());

document.open();

String logoName = "Image.JPG";

Image logo = Image.getInstance(super.getSession().getServletContext().getRealPath("images/"+logoName));

document.add(logo);

Paragraph titleP = new Paragraph(saveFileName,ITextPDFUtil.getTitleFont());

titleP.setAlignment(Element.ALIGN_CENTER);

document.add(titleP);//

Table table = new Table(9);

table.setWidth(100);

table.setWidths(new int[]{2,4,2,4,4,3,3,4,5});

table.setCellspacing(4);

table.setBorder(0);

table.setConvert2pdfptable(true);

Cell cell = null;

cell = ITextPDFUtil.getCell("填表日期",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(1);

table.addCell(cell);

cell = ITextPDFUtil.getCell(DateUtil.toFull(new Date())+"",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("申请部门",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(1);

table.addCell(cell);

cell = ITextPDFUtil.getCell("主材业务处",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("付款公司",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell(paymentCompanyName,font3);

cell.setColspan(3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("结算方式",font3);

cell.setRowspan(2);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("预付",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("□",font3);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

table.addCell(cell);

cell = ITextPDFUtil.getCell("\t\t%,其余于\t\t日支付",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("付款方式",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("内容",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("主材款",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("货到付款",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("□",font3);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

table.addCell(cell);

cell = ITextPDFUtil.getCell("帐期 ",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("合同编号",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell(StringUtil.concatStr(sttlementAccontCodes,","),font3);

cell.setColspan(3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("收款单位",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setRowspan(4);

table.addCell(cell);

cell = ITextPDFUtil.getCell("供应商编码",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell(si.getSupplierCode(),font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(3);

table.addCell(cell);

cell = ITextPDFUtil.getCell("应收票据",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("",font3);

cell.setColspan(3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("供应商名称",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell(si.getSupplierName(),font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(3);

table.addCell(cell);

cell = ITextPDFUtil.getCell("备注",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setRowspan(3);

table.addCell(cell);

cell = ITextPDFUtil.getCell("",font3);

cell.setColspan(3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("",font3);

cell.setColspan(3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("账号",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

if(PersistUtil.isNotEmpty(si)&&PersistUtil.isNotEmpty(si.getBankAccount())){

cell = ITextPDFUtil.getCell(si.getBankAccount(),font3);

}else if(PersistUtil.isNotEmpty(supplierContract)&&PersistUtil.isNotEmpty(supplierContract.getSecondPartyBankAccount())){

cell = ITextPDFUtil.getCell(supplierContract.getSecondPartyBankAccount(),font3);

}else{

cell = ITextPDFUtil.getCell("",font3);

}

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(3);

table.addCell(cell);

cell = ITextPDFUtil.getCell("",font3);

cell.setColspan(3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("大写金额",font3);

cell.setColspan(2);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell(PersistUtil.numToRMBStr(settlementAmount),font3);

cell.setColspan(5);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("小写金额",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

NumberFormat usFormat =NumberFormat.getInstance(Locale.US);

cell = ITextPDFUtil.getCell(usFormat.format(settlementAmount)+"",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("总经理",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("",font3);

cell.setColspan(2);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("部门负责人",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("",font3);

cell.setColspan(2);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("经办人",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("公司领导",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

cell.setColspan(2);

table.addCell(cell);

cell = ITextPDFUtil.getCell("",font3);

cell.setColspan(2);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("财务经理",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("",font3);

cell.setColspan(2);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("财务审核",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

cell = ITextPDFUtil.getCell("",font3);

cell.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(cell);

document.add(table);

document.close();

return null;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐