Reputation: 4004
I am building a pdf from html and I want to set the table border. here is my html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Digital </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body style="font-size:12.0pt; font-family:Arial">
<table style="width:100%" border=\"2\">
<tr>
<th>depo date</th>
<th>MMR</th>
<th>SUM</th>
<th>NUM</th>
<th>ACCOUNT</th>
<th>TNUM</th>
</tr>
<tr>
<td dir="rtl">$data.depo</td>
<td dir="rtl">$data.MR</td>
<td dir="rtl">$data.Sum</td>
<td dir="rtl">$data.Num</td>
<td dir="rtl">$data.accoun</td>
<td dir="rtl">$data.branch</td>
<td dir="rtl">$data.TNum</td>
</tr>
</table>
</body>
</html>
Following iText-add-table-to-pdf, the only diffrence is adding border=\"2\"
to the table, but it still does not work, is there more changes I need to add?
The create pdf function(same is the one on the tutorial):
public void createPdf(String file, String htmlString, String pathToTTF) throws IOException, DocumentException {
// step 1
Document document = new Document();
// step 2
PdfWriter writer =
PdfWriter.getInstance(document, new FileOutputStream(file));
// step 3
document.open();
// step 4
// Styles
CSSResolver cssResolver = new StyleAttrCSSResolver();
XMLWorkerFontProvider fontProvider =
new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS); //
fontProvider.register(pathToTTF);
CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);
HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);
htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
// Pipelines
PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);
// XML Worker
XMLWorker worker = new XMLWorker(css, true);
XMLParser p = new XMLParser(worker);
p.parse(new FileInputStream(htmlString), Charset.forName("UTF-8"));
// step 5
document.close();
}
Upvotes: 0
Views: 760
Reputation: 9057
Please consider using pdfHtml when converting html to pdf.
pdfHtml is the latest tool in our addon-section that does this task, and has a far greater range when it comes to both CSS and HTML constructions.
Upvotes: 1