HTML 转pdf

master
dalong306 5 years ago
parent 75f18f6ffb
commit 18da986c6b

@ -52,6 +52,7 @@ import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.http.util.TextUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
@ -832,9 +833,12 @@ public class TradeLogServiceImpl implements TradeLogService {
: "-";
item.put("debit", debit);
item.put("credit", credit);
if(item.get("settle_amount")==null){
item.put("settle_amount","-");
}
});
System.out.println("------>dataList:"+dataList);
System.out.println("------>parmerters:"+parmerters);
ctx.setVariable("parmerters",parmerters);
ctx.setVariable("dataList",dataList);
final String html = thymeleaf.process("app/invoice.html", ctx);
@ -844,14 +848,14 @@ public class TradeLogServiceImpl implements TradeLogService {
String fileName = client.getString("client_moniker") + "_Cross_Border_" + parmerters.getString("dateRange").replaceAll("/", "");
response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".pdf");
OutputStream outs = response.getOutputStream();
JSONObject clientIncrement = clientIncrementalMapper.findByClinetIdAndChannel(client.getIntValue("client_id"), "RP跨境商城");
// JSONObject clientIncrement = clientIncrementalMapper.findByClinetIdAndChannel(client.getIntValue("client_id"), "RP跨境商城");
// InputStream jasper = clientIncrement == null ? trans_flow.getInputStream() : incremental_trans_flow.getInputStream();
// byte[] bytes = JasperRunManager.runReportToPdf(jasper, parmerters, jrDataSource);
System.out.println("------>content:"+html);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ITextRenderer renderer = new ITextRenderer();
ITextFontResolver fontResolver = (ITextFontResolver) renderer.getSharedContext().getFontResolver();
// ITextFontResolver fontResolver = (ITextFontResolver) renderer.getSharedContext().getFontResolver();
//添加字体库 begin
// File f = new File(fontDir);
// if (f.isDirectory()) {
@ -875,24 +879,6 @@ public class TradeLogServiceImpl implements TradeLogService {
outs.flush();
outs.close();
// final String html = thymeleaf.process("invoice.html", ctx);
// response.setContentType("application/pdf");
// String fileName = client.getString("client_moniker") + "_" + parmerters.getString("dateRange").replaceAll("/", "");
// response.setHeader("Content-Disposition", "attachment;fileName=123.pdf");
// OutputStream outs = null;
// try {
// outs = response.getOutputStream();
//// JSONObject clientIncrement = clientIncrementalMapper.findByClinetIdAndChannel(client.getIntValue("client_id"), "RP跨境商城");
//// InputStream jasper = clientIncrement == null ? trans_flow.getInputStream() : incremental_trans_flow.getInputStream();
//// byte[] bytes = JasperRunManager.runReportToPdf(jasper, parmerters, jrDataSource);
// outs.write(buff, 0, buff.length);
// outs.flush();
// outs.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
} catch (Exception e) {
e.printStackTrace();

@ -72,18 +72,26 @@
height: auto;
font-weight: bold;
}
.divSumary{
child-align: middle;
}
.spancontent-title{
width: 40%;
float: left;
color: #000000;
font-size: 17px;
font-weight: bold;
vertical-align: center;
}
.spancontent-value{
color: #000000;
font-size: 17px;
font-weight: bold;
padding-left: 5px;
vertical-align: center;
}
.hrclass{
background-color: #bf7a12;
@ -98,23 +106,25 @@
<img src="https://mpay.royalpay.com.au/static/images/logo_new.jpg" alt="" width="100px" height="100px"/><br/>
<span>Tunnel Show Pty Ltd trading as RoyalPay</span><br/>
<span>ABN 16 601 619 685 Representative of AFSL 448066</span><br/>
<span th:text="${parmerters.clientName}"></span>
<span th:text="${parmerters.clientName}"></span><br/>
<span th:text="${parmerters.clientAddress}"></span>
</div>
<div class="divcontent_right">
<div style="padding-bottom: 15px">
<span class="spantitle">Tax Invoice </span></div>
<span class="spancontent-title">Merchant code</span><span class="spancontent-value" th:text="${parmerters.partnerCode}"></span>
<span class="spantitle">Tax Invoice </span>
</div>
<div class="divSumary"><span class="spancontent-title">Merchant code</span><span class="spancontent-value" th:text="${parmerters.partnerCode}"></span></div>
<hr class="hrclass"/>
<span class="spancontent-title">Statement</span><span class="spancontent-value" th:text="${parmerters.dateRange}"></span>
<div class="divSumary"> <span class="spancontent-title">Statement</span><span class="spancontent-value" th:text="${parmerters.dateRange}"></span></div>
<hr class="hrclass"/>
<span class="spancontent-title">Issue Date</span><span class="spancontent-value" ></span>
<div class="divSumary"> <span class="spancontent-title">Issue Date</span><span class="spancontent-value" >-</span></div>
<hr class="hrclass"/>
<span class="spancontent-title">Current</span><span class="spancontent-value" th:text="${parmerters.balance}"></span>
<div class="divSumary"> <span class="spancontent-title">Current</span><span class="spancontent-value" th:text="${parmerters.balance}"></span></div>
<hr class="hrclass"/>
</div>
</div>
<div style="padding-bottom: 15px">
<div style="padding-bottom: 1px;padding-top:10px;float: left">
<span class="spantitle">Your Statement </span><br/>
@ -124,15 +134,15 @@
<span>Date/Time</span>
</div>
<div class="divinvoiceItem" style="width: 16%">
<div class="divinvoiceItem" style="width: 22%">
<span>Transaction ID</span>
</div>
<div class="divinvoiceItem" style="width: 13%">
<div class="divinvoiceItem" style="width: 10%">
<span>Debit</span>
</div>
<div class="divinvoiceItem" style="width: 13%">
<div class="divinvoiceItem" style="width: 10%">
<span>Credit</span>
</div>
@ -140,40 +150,40 @@
<span>Service Fee for RoyalPay (GST inclu)</span>
</div>
<div class="divinvoiceItem" style="width: 14%">
<div class="divinvoiceItem" style="width: 12%">
<span>Service fee for Mini Program(GST Inclu)</span>
</div>
<div class="divinvoiceItem" style="width: 10%">
<div class="divinvoiceItem" style="width: 11%">
<span>Settlement Amount</span>
</div>
</div>
<div th:each="invoicedata:${dataList}">
<div class="divinvoicesContent">
<div class="divinvoiceItem" style="width: 16%">
<span th:text="${invoicedata.transaction_time}"></span>
<span th:text="${invoicedata.transaction_time}?:'-'"></span>
</div>
<div class="divinvoiceItem" style="width: 16%">
<span th:text="${invoicedata.order_id}"></span>
<div class="divinvoiceItem" style="width: 22%">
<span th:text="${invoicedata.order_id}?:'-'"></span>
</div>
<div class="divinvoiceItem" style="width: 13%">
<span th:text="${invoicedata.debit}"></span>
<div class="divinvoiceItem" style="width: 10%;padding-left: 10px" >
<span th:text="${invoicedata.debit}?:'-'">-</span>
</div>
<div class="divinvoiceItem" style="width: 13%">
<span th:text="${invoicedata.credit}">Credit</span>
<div class="divinvoiceItem" style="width: 10%">
<span th:text="${invoicedata.credit}?:'-'">-</span>
</div>
<div class="divinvoiceItem" style="width: 14%">
<span th:text="${invoicedata.real_royalpay_surcharge}"></span>
<span th:text="${invoicedata.real_royalpay_surcharge}?:'-'"></span>
</div>
<div class="divinvoiceItem" style="width: 14%">
<span th:text="${invoicedata.incremental_surcharge}"></span>
<div class="divinvoiceItem" style="width: 12%">
<span th:text="${invoicedata.incremental_surcharge}?:'-'"></span>
</div>
<div class="divinvoiceItem" style="width: 10%">
<span th:text="${invoicedata.settle_amount}" ></span>
<div class="divinvoiceItem" style="width: 11%">
<span th:text="${invoicedata.settle_amount}?:'-'" ></span>
</div>
</div>

Loading…
Cancel
Save