如何从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 。
更新
好的,我发现了一个article并尝试在其帮助下实现垂直文本。
但是如何将它与上面的代码相关联?
更新
Further as a point of note
-
我的html包含一些我后来使用程序替换的元素。这些元素由html标签内的大括号表示,如<td>{VERTICALTEXT}</td>
。然后在程序中我用地图替换它像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的新手。
谢谢!