将CSS样式添加到iTextSharp PDF输出中

时间:2017-11-13 13:34:39

标签: c# itext

我试图找出如何在我的代码生成的pdf输出上使用我的Tables.css。

这是我的代码:

public FileResult Edit(SpiseKopunTable model)
    {
        bool b = repository.PutSpiseKopun(model);
        DateTime d = new DateTime(1980, 1, 1);
        DateTime.TryParse(model.Dato.ToString(), out d);
        int c = new int();
        int.TryParse(model.ID.ToString(), out c);
        int e = new int();
        int.TryParse(model.Antal_Kuponer.ToString(), out e);

        using (MemoryStream stream = new System.IO.MemoryStream())
        {   
            int Antal_Kuponer = e;
            string SpiseTable = String.Format("<table><tbody><tr><td>GL:{0}</td></ tr >< tr >< td > Service:{1}</ td ></ tr >< tr >< td > Dato:{2}</ td ></ tr >< tr >< td > Pris:{3}</ td ></ tr >< tr >< td > Kommentar:{4}</ td ></ tr><tr><td> ID:{5}</ td ></ tr ></ tbody ></ table >",
                            model.GL,
                            model.Service,
                            d.ToString("dd-MM-yyyy"),
                            model.Pris,
                            model.Kommentar,
                            c.ToString()
                            );
            StringReader sr = new StringReader(
                 new StringBuilder().Insert(0, SpiseTable, e).ToString()

            );
            Document pdfDoc = new Document(PageSize.A4, 40, 40, 20, 20);
            PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
            //Console.WriteLine(sr);
            pdfDoc.Open();

            XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
            pdfDoc.Close();
            return File(stream.ToArray(), "application/pdf", "Airgreenland-vouchers.pdf");
        }
    }

我查看了iTextSharp表样式的官方示例,但我无法使其在我的代码上运行。

此致 Erneeraq Fleischer

0 个答案:

没有答案