0

How is it possible to set the text vertically starting from bottom to top?

These are dynamically generated texts. So I considered putting each text in a tags in a table.

This isn't working:

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>";
}

enter image description here

The style used here for vertical alignment is not working for itextpdf.

UPDATE:

Ok, I found one article and trying to implement the verticle text with its help.

But how to link it with my above code ?

UPDATE:

Further as a point of note-

My html contains some elements which I am replacing later using program. Such elements are denoted by under braces inside html tags like <td>{VERTICALTEXT}</td>. Then in program I am replacing this by map like- map.put("VERTICALTEXT", verticalLoc);. Then its html = html.replace("{" + e.getKey() + "}", value); to replace and get required html.

UPDATE:

How I am doing that-

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);

Can I still use Canvas to rotate the text and pass in map further for display ?

Please help as I am new to android Canvas and itextpdf.

Thanks!

Community
  • 1
  • 1
sjain
  • 23,126
  • 28
  • 107
  • 185
  • Why are you using the ´VerticalText´ class for drawing Western text. The `VerticalText` class is to be used for special writing systems, such as Japanese or Chinese. When I look at your screen shot, I don't see vertical text. I see text that is simply rotated. Also: is your question about Android (screen shot) or about iText? That's not clear. – Bruno Lowagie Nov 20 '13 at 08:05
  • @BrunoLowagie- I used this just as a hit and trial way to get the vertical text. Probably that's the wrong way. However, I am using iText in my android application to generate Pdf from html. The way I want the text in my generated Pdf should be like the one in screenshot. – sjain Nov 20 '13 at 08:22
  • @BrunoLowagie- Further as a point of note- My html contains some elements which I am replacing later using program. Such elements are denoted by under braces inside html tags like `{VERTICALTEXT}`. Then in program I am replacing this by map like- `map.put("VERTICALTEXT", verticalLoc);`. Then its `html = html.replace("{" + e.getKey() + "}", value);` to replace and get required html. Can I still use `Canvas` to rotate the text and pass in map further for display ? – sjain Nov 20 '13 at 08:26
  • @BrunoLowagie- I am able to generate Pdf from html using iText. The only thing I am unable to get is the vertical text. It seems that iText isn't supporting the styles like `-ms-transform:rotate(270deg);` to rotate the text in html. How to achieve this ? – sjain Nov 20 '13 at 08:39
  • Part of the confusion is that you talk about vertical text when you actually mean rotated text. There's a huge difference! Furthermore, I don't know how (or even why) you're converting the HTML to PDF. Rotating the contents of a cell is done like this: `cell.setRotation(90);` See http://itextpdf.com/examples/iia.php?id=82 and http://examples.itextpdf.com/results/part1/chapter04/rotation_colors.pdf for an example. – Bruno Lowagie Nov 20 '13 at 11:26
  • @BrunoLowagie- Updated my question. So pls look the shortened code of how I am doing that. I just put all html content in a file `FILE` and which is then converted to pdf by iText. The idea you mentioned looks great but how do I embed the cell generated by program to my `My_Report.html` at specified tag location ? – sjain Nov 20 '13 at 12:26
  • You don't. You're using `HtmlWorker` which is a deprecated class (meaning it's no longer supported). – Bruno Lowagie Nov 20 '13 at 13:03
  • @BrunoLowagie - Now that I used `cell.setRotation(90)`, I found that the text is rotated fine. The problem now is - how to place this rotated text cell in html string form in order to show this whole html later in pdf form. Please check this problem as seperate question on SO here - http://stackoverflow.com/questions/20516989/how-to-add-a-pdfptable-to-the-html-string-dynamically-in-itext – sjain Dec 11 '13 at 11:11

0 Answers0