java 写 pdf 方式

这篇博客主要介绍了如何在Java中创建PDF文件,从JSP页面出发,通过Action调用来实现这一过程,虽然没有详细展示接口代码,但重点在于实际的实现类部分。
摘要由CSDN通过智能技术生成

jsp 页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!doctype html>
<html>
<head>
<%@ include file="/WEB-INF/pages/globalweb/head/pagehead_v5.ini"%>
</head>
<body>


<iframe src="" marginwidth="0" target="_self"  id="faFrame"
	marginheight="0" frameborder="0" width="100%" height="945px" 
     style="overflow-x: hidden; overflow-y: auto;">

</iframe>

</body>
<script type="text/javascript">
	$("#faFrame").attr("src",$.getURL(_path + "/fagl/faxxck_dyxx.html? 
   id=${faxx_id}"+'&dlbs='+$("#dlbs").val()));
	
</script>
</html>


Action 调用

	public String dyxx(){
		ByteArrayOutputStream bous = null;
		try{
				StringBuffer title = new StringBuffer("");
				title.append(faxxckModel.getfamc());
				//开始生成pdf
				bous = service.createPdf(title,faxxckModel);

				this.fileName = new String((title.toString() + ".pdf").getBytes(), "ISO8859-1");
				this.inputStream = new ByteArrayInputStream(bous.toByteArray());
				return Result.PDF_INLINE;
		} catch (Exception e) {
			logException(e);
			return ERROR;
		}finally{
			IOUtils.closeQuietly(bous);
		}
	}

接口不写了

直接 实现类

@Override
	public ByteArrayOutputStream createPdf(Pyfaxx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java使用com.lowagie.text.pdf插件编PDF报表工具类,支持动态报表创建,使用简单,附件中包含了测试类和生成的报表文件。附件中的代码需要修改相关的保存路径后可以直接使用。创建一张报表例子: private JsFileExportResult createRowReport() { String condition = "开始时间:2018-02-02 14:00:30 结束时间:2018-02-06 16:00:30"; PDFGridReport pdfReport = new PDFGridReport("报表创建测试", GridReportTestModel.getModels()); pdfReport.addCondition(condition); pdfReport.header("字段名称1", "item1", 0, 0).width(160); pdfReport.header("字段名称3", "item3", 0, 2).getCell().backgroundColor(Color.ORANGE); pdfReport.header("字段名称4", "item4", 0, 3); pdfReport.header("字段名称5", "item5", 0, 4); pdfReport.header("字段名称2", "item2", 0, 1); pdfReport.header("值", "value", 0, 5).alignH(HAlign.ALIGN_CENTER).getCell().alignH(HAlign.ALIGN_RIGHT); pdfReport.header("时间", "time", 0, 6); pdfReport.header("图片", "image", 0, 7).width(60).alignH(HAlign.ALIGN_CENTER).getCell() .alignH(HAlign.ALIGN_CENTER).alignV(VAlign.ALIGN_MIDDLE); // 横向打印 pdfReport.getPageSetting().setPrintHorizontal(); pdfReport.group("item1").childGroup("item2"); pdfReport.setCellFormat(new PDFCellValueFormat() { @Override public String format(String fieldName, String oriValue) { if ("value".equals(fieldName)) { return String.format("%.2f", Double.parseDouble(oriValue)).toString(); } else { return oriValue; } } }); JsFileExportResult fileResult = pdfReport.createReport(); return fileResult; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值