2
我有一個帶有文本字段和複選框的XHTML文件;當我試圖將我的xhtml轉換爲使用ITextRenderer的pdf; iText正在放棄表單域(如pdf中的複選框和文本框)。itext將xhtml轉換爲pdf
我的代碼看起來
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(new File("input.xhtml").toURI().toURL.toString());
renderer.layout();
renderer.createPDF("outputstream");
有人能提供的示例代碼段來處理利用iText上面的場景;我正在使用iText 5.1.3版本。
我的XHTML看起來像
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>FULL</title>
<style media="screen" type="text/css">
fieldset table { width:98%;border: 1px groove; margin:0 auto; }
fieldset table tr { border: 1px groove; }
fieldset table th { border: 1px groove; }
fieldset table td { border: 1px groove; }
fieldset > table [id=inspectionStatus] thead {border: 1px groove;background:#446BEC;text-align:center;}
fieldset > table [id=inspectionStatus] tr { border: 1px groove; }
fieldset > table [id=inspectionStatus] th { border: 1px groove; }
fieldset > table [id=inspectionStatus] td { border: 1px groove; }
fieldset table thead {border: 1px groove;background:#446BEC;text-align:center;}
fieldset table tbody tr th {text-align:left;background:#C6DEFF;width:28%}
fieldset table tbody tr td {text-align:center} [type=text] {margin-left:5%;} *[type=text]{width:90%;}
fieldset table tbody tr td [type=checkbox] {margin:0 auto;} *[type=checkbox]{width:90%;}
fieldset table caption {font-weight:bold;color:#0840F8;}
fieldset {width:98%;font-weight:bold;border:1px solid #446BEC;}
</style>
</head>
<body>
<fieldset id="PersonTable">
<legend>Person Information</legend>
<table id="PersonDisplay">
<thead>
<tr>
<th>Identifier</th>
<th>Name</th>
<th>Comment</th>
<th>Pass</th>
<th>Fail</th>
</tr>
</thead>
<tbody>
<tr>
<td>1234</td>
<td> William Jones</td>
<td>
<input type="text"/>
</td>
<td>
<input type="checkbox"/>
</td>
<td>
<input type="checkbox"/>
</td>
</tr>
</tbody>
</table>
</fieldset>
</body>
</html>
那麼你的'input.xhtml'文件是什麼樣子? –
我已經更新了上面的描述以顯示我想要轉換爲PDF的示例XHTML –
另外,請注意renderer.setDocument(new File(「input.xhtml」).toURI()。toURL.toString()); 不會爲您提供文件內容。它只是給你文件路徑(在這種情況下作爲URI)。 –