0

I am trying to find out how i can use my Tables.css on the pdf output that my code makes.

Here is my code:

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

I have looked at the official examples from iTextSharp tables styling, but i can't make it work on my code.

Regards Erneeraq Fleischer

  • Your code doesn't reflect your allegation "I have looked at the official examples." Are you sure you've looked at [How to get particular html table contents to write it in pdf using itext](http://stackoverflow.com/questions/24530852/), [RowSpan does not work in iTextSharp?](https://stackoverflow.com/questions/26679003/), [How to add external CSS while generating PDF?](https://stackoverflow.com/questions/24777549), and other Stack Overflow questions referenced from the [FAQ](https://developers.itextpdf.com/content/best-itext-questions-stackoverview/parsing-xml-and-xhtml)? – Bruno Lowagie Nov 13 '17 at 13:39
  • Also, since you are working for Air Greenland, and since you are using the AGPL version of iTextSharp, I want to inform you that Air Greenland will have to publish all the code you write publicly as AGPL software. If this isn't an option Air Greenland will have to purchase a commercial license. In that case, would it be better if you wrote your code using iText 7 and pdfHTML instead of using iText 5 and XML Worker? – Bruno Lowagie Nov 13 '17 at 13:41

0 Answers0