Using itextsharp xmlworker to convert html to pdf and write text vertically

后端 未结 2 508
盖世英雄少女心
盖世英雄少女心 2021-02-08 11:42

Is there possible to achieve writing text direction bottom-up in xmlworker? I would like to use it in table. My code is

     
2条回答
  •  迷失自我
    2021-02-08 11:53

    public void addHtmlToPdf(Document document, PdfWriter writer, String html) {
        PdfPTable table = new PdfPTable(1);
        PdfPCell cell = new PdfPCell();
        ElementList list = XMLWorkerHelper.ParseToElementList(html, null);
        foreach(IElement element in list) {
            cell.AddElement(element);
        }
        table.AddCell(cell);
        document.Add(table);
    }
    

    Alternative with utf8:

    public void addHtmlToPdf_Utf8(Document document, PdfWriter writer, String html) 
    {
        XMLWorkerHelper xml = XMLWorkerHelper.GetInstance();
        xml.ParseXHtml(writer, document, stringToStream(html), System.Text.Encoding.UTF8);
    }
    public Stream stringToStream(string txt) {
        var stream = new MemoryStream();
        var w = new StreamWriter(stream);
        w.Write(txt);
        w.Flush();
        stream.Position = 0;
        return stream;
    }
    

提交回复
热议问题