public String createDataPDF(){
List<HashMap<String, String>> options=new ArrayList<HashMap<String,String>>();
//post参数
HashMap<String,String> orderId=new HashMap<String, String>();
orderId.put("optionName", "--post order.orderId");
orderId.put("optionValue",this.order.getOrderId()+"");
HashMap<String,String> deliveryTime=new HashMap<String, String>();
deliveryTime.put("optionName", "--post order.deliveryTime");
deliveryTime.put("optionValue",BASE64Util.encode(this.order.getDeliveryTime()+""));
HashMap<String,String> productName=new HashMap<String, String>();
productName.put("optionName", "--post order.productName");
productName.put("optionValue",BASE64Util.encode(this.order.getProductName()));
HashMap<String,String> status=new HashMap<String, String>();
status.put("optionName", "--post order.status");
status.put("optionValue",BASE64Util.encode(this.order.getStatus()));
HashMap<String,String> pageSize=new HashMap<String, String>();
pageSize.put("optionName", "--page-size");
pageSize.put("optionValue","a4");
options.add(orderId);
options.add(deliveryTime);
options.add(productName);
options.add(status);
options.add(pageSize);
this.wkhtmltopdf.setFileName("order.pdf");
this.wkhtmltopdf.setObjectPrintUrl("http://localhost:8080/PDFTest/create_PDF.action");
this.wkhtmltopdf.setOptions(options);
String temp= ServletActionContext.getServletContext().getRealPath("/");
String pdfRealyPath=temp+"pdfFile\\";
PDFToll pdfToll=new PDFToll(this.wkhtmltopdf);
pdfToll.createPDF(pdfRealyPath);
return SUCCESS;
}
<struts>
<!-- 设置编码格式 -->
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<!-- 创建 -->
<package name="pdfTest" extends="struts-default">
<action name="create_PDF" method="createPDF" class="com.test.action.CreatePDF">
<result name="success">/objectPage.jsp</result>
</action>
<!-- 创建一个带参数的pdf -->
<action name="create_Data_PDF" method="createDataPDF" class="com.test.action.PrintPageWithData">
<result type="redirectAction">
download_PDF?wkhtmltopdf.fileName=${wkhtmltopdf.fileName}
</result>
</action>
<!-- 下载 -->
<action name="download_PDF" class="com.test.action.PDFPrint">
<result name="success" type="stream">
<param name="contentType">application/pdf;charset=ISO8859-1</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${wkhtmltopdf.fileName}"</param>
<param name="bufferSize">4096</param>
</result>
</action>
</package>
</struts>
//跳转到目标页面
public String createPDF() throws UnsupportedEncodingException{
this.order.setProductName(BASE64Util.decode(this.order.getProductName()));
this.order.setDeliveryTime(BASE64Util.decode(this.order.getDeliveryTime()));
this.order.setStatus(BASE64Util.decode(this.order.getStatus()));
System.out.println(this.order.getDeliveryTime()+"\n"+BASE64Util.decode(this.order.getDeliveryTime())+"\n"+BASE64Util.getFromBASE64(this.order.getDeliveryTime()));
return SUCCESS;
}
ps:我用base64转了下码发现也不行,具体原因也不是很清楚,各位有没有遇到这种情况