如何从 开始垂直设置文本bottom to top
?
这些是动态生成的文本。所以我考虑将每个文本放在表格中的标签中。
这不起作用:
for (int j = 0; j < cur.getCount(); j++)
{
VerticalText vt = new VerticalText(writer.getDirectContent());
//vt.setVerticalLayout(390, 570, 540, 12, 30);
vt.addText(new Phrase(location));
vt.go();
vt.setAlignment(Element.ALIGN_RIGHT);
verticalLoc = vt.toString();
verticalLoc += "<td align='left' width='28%'><div style='font-size:8px;-ms-transform:rotate(270deg);-moz-transform:rotate(270deg);" +
"-webkit-transform:rotate(270deg);-o-transform:rotate(270deg);'>"+ verticalLoc+ "</div></td>";
}
此处用于垂直对齐的样式不适用于itextpdf。
更新:
好的,我找到了一篇文章并尝试在它的帮助下实现垂直文本。
但是如何将它与我上面的代码联系起来呢?
更新:
Further as a point of note
-
我的 html 包含一些我稍后使用程序替换的元素。此类元素由 html 标签内的大括号表示,例如<td>{VERTICALTEXT}</td>
. 然后在程序中,我将其替换为 map like- map.put("VERTICALTEXT", verticalLoc);
。然后它html = html.replace("{" + e.getKey() + "}", value);
替换并获取所需的html。
更新:
我是怎么做到的——
private static String FILE = Environment.getExternalStorageDirectory() + File.separator;
static PdfWriter writer;
HTMLWorker htmlWorker = new HTMLWorker(document);
Document document = new Document();
document.setMargins(2f, 2f, 2f, 2f);
writer = PdfWriter.getInstance(document, new FileOutputStream(FILE));
document.open();
PdfDestination pdfDest = new PdfDestination(PdfDestination.FIT, 0,
document.getPageSize().getHeight(), 0.5f);
PdfAction action = PdfAction.gotoLocalPage(1, pdfDest, writer);
writer.setOpenAction(action);
verticalLoc += "<td align='left' width='28%'><div style='font-size:8px;-ms-transform:rotate(270deg);-moz-transform:rotate(270deg);" +"-webkit-transform:rotate(270deg);-o-transform:rotate(270deg);'>"+ location+ "</div></td>";
InputStream is = getAssets().open("My_Report.html");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
map.put("VERTICALTEXT", verticalLoc);
map.put("STATE", getvalue("State", "Information", ""));
map.put("TIMEZONE", getvalue("Time_Zone", "Information", ""));
String htmlStr = getHTMLReport(new String(buffer), map);
htmlWorker.parse(new StringReader(htmlStr));
PdfContentByte cb = writer.getDirectContent();
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.saveState();
cb.beginText();
cb.moveText(x, y);
cb.setFontAndSize(bf, 12);
cb.showText(text);
cb.endText();
cb.restoreState();
document.newPage();
document.close();
openPdfIntent(FILE);
我还可以使用 Canvas 旋转文本并进一步传入地图以进行显示吗?
请帮助,因为我是 android Canvas 和 itextpdf 的新手。
谢谢!