XmlWorker itextsharp在div之间添加img标签base64

时间:2018-01-19 08:38:28

标签: c#-4.0 itext

这里我的html包含表格中的多个div,div我会显示可以很容易理解的代码部分。

   <div class="col-xs-12 m-t-3">
        <div class="col-xs-4">
            <-- I want to insert img tag here which i'm converting from base64-->
        </div>
        <div class="col-xs-5 pull-right">
            <table class="table table-condensed">
                <tbody>
                    <tr>
                        <td><strong>Account #</strong></td>
                    </tr>
                    <tr>
                        <td><strong>857456</strong></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

我得到的PDF截图:

iText Render issue

我使用的C#代码:

var inputString = System.IO.File.ReadAllText(@"E:\Projects\Epic_Setup\XYZApp\XYZConsole\InvoiceView.html");
var output = new MemoryStream();
var input = new MemoryStream(Encoding.UTF8.GetBytes(inputString));
var document = new Document(iTextSharp.text.PageSize.A4, 10, 10, 10, 10);
var writer = PdfWriter.GetInstance(document, output);
document.Open();
iTextSharp.text.Image gif = null;
string base64string = "base64string";
//  Convert base64string to bytes array
Byte[] bytes = Convert.FromBase64String(base64string);
gif = iTextSharp.text.Image.GetInstance(bytes);             
var pipeline = new iTextSharp.tool.xml.pipeline.css.CssResolverPipeline(cssResolver, new iTextSharp.tool.xml.pipeline.html.HtmlPipeline(htmlContext, new iTextSharp.tool.xml.pipeline.end.PdfWriterPipeline(document, writer)));
var worker = new XMLWorker(pipeline, true);
var p = new iTextSharp.tool.xml.parser.XMLParser(worker);            
document.Add(gif);
p.Parse(input);
//XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, inputString);            
document.Close();
output.Position = 0;
byte[] byteArray = output.ToArray();

0 个答案:

没有答案