|
|
|
@ -7,6 +7,10 @@ import freemarker.template.TemplateExceptionHandler;
|
|
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.w3c.dom.Document; |
|
|
|
|
import org.xhtmlrenderer.css.value.FontSpecification; |
|
|
|
|
import org.xhtmlrenderer.extend.FontResolver; |
|
|
|
|
import org.xhtmlrenderer.layout.SharedContext; |
|
|
|
|
import org.xhtmlrenderer.render.FSFont; |
|
|
|
|
import org.xhtmlrenderer.swing.Java2DRenderer; |
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
@ -14,10 +18,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import javax.xml.parsers.DocumentBuilder; |
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory; |
|
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.io.StringWriter; |
|
|
|
|
import java.io.*; |
|
|
|
|
import java.net.HttpURLConnection; |
|
|
|
|
import java.net.URL; |
|
|
|
|
import java.util.Map; |
|
|
|
@ -93,12 +94,15 @@ public class TemplateUtil {
|
|
|
|
|
BufferedImage img =null; |
|
|
|
|
try { |
|
|
|
|
html = getTemplateByUrl(template, map,url); |
|
|
|
|
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+html); |
|
|
|
|
byte[] bytes=html.getBytes(); |
|
|
|
|
ByteArrayInputStream bin=new ByteArrayInputStream(bytes); |
|
|
|
|
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); |
|
|
|
|
DocumentBuilder builder=factory.newDocumentBuilder(); |
|
|
|
|
|
|
|
|
|
Document document=builder.parse(bin); |
|
|
|
|
Java2DRenderer renderer = new Java2DRenderer(document,width,height); |
|
|
|
|
|
|
|
|
|
img = renderer.getImage(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
@ -106,6 +110,106 @@ public class TemplateUtil {
|
|
|
|
|
return img; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static BufferedImage makePic(Integer width,Integer height){ |
|
|
|
|
String html = null; |
|
|
|
|
BufferedImage img =null; |
|
|
|
|
try { |
|
|
|
|
// html = getTemplateByUrl(template, map,url);
|
|
|
|
|
html = "<html>\n" + |
|
|
|
|
" <header>\n" + |
|
|
|
|
" <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\n" + |
|
|
|
|
" </header>\n" + |
|
|
|
|
" <body>\n" + |
|
|
|
|
"<table>\n" + |
|
|
|
|
" <div id=\"print-iframe\" style=\"height: 330px;width:600px;border: 1px solid #e2ce1d\">\n" + |
|
|
|
|
" <div style=\"height: 20px; border-bottom: 1px solid black;text-align: center \">包条码</div>\n" + |
|
|
|
|
" <div style=\"border-bottom: 1px solid black;height: 50px\">\n" + |
|
|
|
|
" <div style=\"height: 50px;padding-top: 10px\" >\n" + |
|
|
|
|
" <img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAeCAIAAABVOSykAAAAaElEQVR42u3QQQrAIAwEwPz/0yko\n" + |
|
|
|
|
"FdEoPZfJQWJwJUxEq8zsZ2/GcLkuTRnMt8r5Pbi//JIaw5jqtPnlt3KZPQULFixYsGDBggULFixY\n" + |
|
|
|
|
"sGDBggULFixYsGDBggULFixYsGDBggXrd1gPnDAPxD/wTuUAAAAASUVORK5CYII=\"/>\n" + |
|
|
|
|
" <div style=\"position: relative;left: 120px;top: -40px;width: 450px\">\n" + |
|
|
|
|
" <div>发站仓:</div>\n" + |
|
|
|
|
" <span>目的仓:</span>\n" + |
|
|
|
|
" <span style=\"float: right\">经销商编码:S009177 广汉市TJH</span>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
"\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
" <div style=\"border-bottom: 1px solid black;width: 550px\">\n" + |
|
|
|
|
" <span style=\"width: 100px;border-right: 1px solid black;\">运单号</span>\n" + |
|
|
|
|
" <span style=\"width: 100px;border-right: 1px solid black;\">QY23080004</span>\n" + |
|
|
|
|
" <span style=\"width: 100px;border-right: 1px solid black;\">订单自编号</span>\n" + |
|
|
|
|
" <span style=\"width: 100px;\">BNLZC广汉市230500001CA1-1遗4</span>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
" <div style=\"height: 60px;width: 240px;border-bottom: 1px solid black\">\n" + |
|
|
|
|
" <div style=\"width: 30px;height: 70px;line-height:60px; border-right: 1px solid black;\">寄</div>\n" + |
|
|
|
|
" <div style=\"width: 460px;position: absolute;left: 50px;top:120px;\"></div>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
" <div style=\"border: 1px solid #635f5f;width: 120px;height: 135px;position:absolute;left:240px ; top:100px;display: block\">\n" + |
|
|
|
|
" <div>\n" + |
|
|
|
|
" <img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAABP0lEQVR42u3aQRLEIAgEwPz/07tf\n" + |
|
|
|
|
"SBUMhqQ5p4z2QVG4fuJ2XAhgwYIFCxYsBA1YVyDujH9nPpPzhAUL1j6s0qYYHmdynrBgwdqHVdnI\n" + |
|
|
|
|
"K+OcmicsWLBgVRNgWLBgwTqJlUhKYcGCBSu1yMq/PvHqAAsWrEcVLNIb+auqO7BgwToe6YS2bZ6w\n" + |
|
|
|
|
"YMF6LFbXAioNIF3NI13rggUL1g6sSIIXKKwmvoEFC9Y+rEnQyWbceFIKCxasMayuxLLrYjyJDgsW\n" + |
|
|
|
|
"rPdjTSaoict8W8ECFixYx7EmixRdKF2XdliwYO3AekJjSNf4bcUXWLBgrcBKb+STh0DpX7BgwVqH\n" + |
|
|
|
|
"lX6Ee1rjLyxYsGClDoT4IQALFqzPYiUKHPFCCSxYsNZhpS/DiaaSV706wIIF63jBoqvRIzFPWLBg\n" + |
|
|
|
|
"7cASsGDBggULloBVij9p++knziTP9AAAAABJRU5ErkJggg==\"/>\n" + |
|
|
|
|
" <span>23072200246-1</span>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
" <div style=\"border: 1px solid #635f5f;width: 195px;height: 135px;position:absolute;left:360px ; top:100px;display: block\">\n" + |
|
|
|
|
" <div>\n" + |
|
|
|
|
" <div >橱柜/橱柜配件/百货小配件</div>\n" + |
|
|
|
|
" <div>OP-ZT001-A/U形枕</div>\n" + |
|
|
|
|
" <div >运单件数:</div>\n" + |
|
|
|
|
" <div>订单总件数:1</div>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
" <div style=\"height: 130px\">\n" + |
|
|
|
|
" <div style=\"width:30px;height: 130px;line-height:130px; border-right: 1px solid black;\">收</div>\n" + |
|
|
|
|
" <div style=\"width: 300px;\">\n" + |
|
|
|
|
" <div style=\"width: 520px;height: 70px; border-bottom: 1px solid black;position: absolute;left: 40px;top: 165px\">\n" + |
|
|
|
|
" <div style=\"width: 30px; border-right: 1px solid black;height: 70px;\">商场</div>\n" + |
|
|
|
|
" <div style=\"position: relative;left: 35px;top: -45px\">德阳欧派大家居</div>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
" <div style=\"width: 500px;height: 60px;position: absolute;left: 40px;top: 240px;margin-top: 0px\">\n" + |
|
|
|
|
" <div style=\"width: 30px; border-right: 1px solid black;height: 60px;\">客户</div>\n" + |
|
|
|
|
" <div style=\"position: relative;left: 35px;top: -60px\">\n" + |
|
|
|
|
" <div >周利平</div>\n" + |
|
|
|
|
" <div >18990272565</div>\n" + |
|
|
|
|
" <div >中国四川省德阳市广汉市,金科25栋3单元1001</div>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
"\n" + |
|
|
|
|
"\n" + |
|
|
|
|
" </div>\n" + |
|
|
|
|
"</table>\n" + |
|
|
|
|
"</body>\n" + |
|
|
|
|
"</html>\n" ; |
|
|
|
|
byte[] bytes=html.getBytes(); |
|
|
|
|
ByteArrayInputStream bin=new ByteArrayInputStream(bytes); |
|
|
|
|
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); |
|
|
|
|
DocumentBuilder builder=factory.newDocumentBuilder(); |
|
|
|
|
Document document=builder.parse(bin); |
|
|
|
|
Java2DRenderer renderer = new Java2DRenderer(document,width,height); |
|
|
|
|
img = renderer.getImage(); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
File file = new File("f://11.png"); |
|
|
|
|
ImageIO.write(img, "png", file); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
return img; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* ftl模板生成图片 |
|
|
|
|
* @param template |
|
|
|
@ -178,4 +282,11 @@ public class TemplateUtil {
|
|
|
|
|
return DestImage; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
|
|
|
|
makePic(120, 300); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|