【发布时间】:2016-05-28 12:08:04
【问题描述】:
我正在使用飞碟将 HTML 转换为 PDF。我想在我的 HTML 中使用 HTML Input 属性,如 CheckBox 并在生成的 PDF 中打印它。但是当我在 html 中编写复选框代码并生成 PDF 时,PDF 中没有打印复选框。
<?xml version="1.0" encoding="utf-8" ?>
<html>
<input type="checkbox" name="vehicle" value="Bike"> I have a bike
<input type="checkbox" name="vehicle" value="Car" checked> I have a car
</html>
包:
this.File = Packages.java.io.File;
this.StringWriter = Packages.java.io.StringWriter;
this.FileOutputStream = Packages.java.io.FileOutputStream;
this.ByteArrayOutputStream = Packages.java.io.ByteArrayOutputStream;
this.ByteArrayInputStream = Packages.java.io.ByteArrayInputStream;
this.HttpClient = Packages.org.apache.commons.httpclient.HttpClient;
this.UsernamePasswordCredentials = Packages.org.apache.commons.httpclient.UsernamePasswordCredentials;
this.Protocol = Packages.org.apache.commons.httpclient.protocol.Protocol;
this.SSLProtocolSocketFactory = Packages.org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory;
this.AuthScope = Packages.org.apache.commons.httpclient.auth.AuthScope;
this.GetMethod = Packages.org.apache.commons.httpclient.methods.GetMethod;
this.PostMethod = Packages.org.apache.commons.httpclient.methods.PostMethod;
this.StringUtil = Packages.com.glide.util.StringUtil;
this.StringEntity = Packages.org.apache.http.entity.StringEntity;
this.SimpleDateFormat = Packages.java.text.SimpleDateFormat;
this.TimeZone = Packages.java.util.TimeZone;
this.Date = Packages.java.util.Date;
// Flying saucer jar references
//
this.tidy = Packages.org.w3c.tidy.Tidy;
this.domDocument = Packages.org.w3c.dom.Document;
this.XHTMLPanel = Packages.org.xhtmlrenderer.simple.XHTMLPanel;
this.iTextRenderer = Packages.org.xhtmlrenderer.pdf.ITextRenderer;
var bos = new this.ByteArrayOutputStream();
var inputString = this.htmlResponse;
this.debug("HTML RESPONSE" + inputString);
var inputStream = new this.ByteArrayInputStream(inputString.getBytes());
var outputForPdfStream = new this.ByteArrayOutputStream();
// tidy the html
var domdoc = this.domDocument;
var iTidy = new this.tidy();
iTidy.setShowWarnings(false);
iTidy.setXmlTags(false);
iTidy.setInputEncoding("UTF-8");
iTidy.setOutputEncoding("UTF-8");
iTidy.setXHTML(true);//
iTidy.setMakeClean(true);
domdoc = iTidy.parseDOM(inputStream, outputForPdfStream);
// Convert the document to XHTML panel and then rendering it into a PDF
var xhtmlPanel = new this.XHTMLPanel();
xhtmlPanel.setDocument(domdoc);
var renderer = new this.iTextRenderer();
renderer.setDocument(xhtmlPanel.getDocument(), null);
renderer.layout();
renderer.createPDF(bos);
bos.flush();
inputStream.close();
this.debug("INPUT STREAM" + inputStream);
var byteArray = bos.toByteArray();
var encodedString = this.StringUtil.base64Encode(byteArray);
this.debug("Encoded String" + encodedString);
我是否需要使用任何特定的包来打印 PDF 中的复选框。请让我知道,如果你有任何问题。任何帮助,将不胜感激。谢谢。
【问题讨论】:
标签: pdf-generation itextsharp itext flying-saucer html-to-pdf