0

I am trying to generate a PDF using iTextSharp in my MVC4 application. I am using an html file, fill data in it and generate the PDF. But there is a problem rendering ordered list of type = "a". the code is something like below:

<ol style="font-size: 10px">
        <li>First</li>
        <li>Second</li>
        <li>Third
            <ol type="a">
                <li>3.1</li>
                <li>3.2</li>
            </ol>
        </li>
        <li>Fourth</li>
</ol>

This should be displayed like below:

1. First
2. Second
3. Third
  a. 3.1
  b. 3.2
4. Fourth

But it is shown as:

1. First
2. Second
3. Third
  1. 3.1
  2. 3.2
4. Fourth

Even if I remove the nesting and just try to render a ordered list of type "a" like below:

<ol type="a">
        <li>First</li>
        <li>Second</li>
        <li>Third</li>
</ol>

still the list shown in PDF is like:

1. First
2. Second
3. Third

there should be a, b, c... instead of 1, 2, 3....
Is it a known issue of iTextSharp?
Is there any solution to the problem??

Thanks.

Edit: the code to generate PDF in controller is:

public ActionResult GeneratePDF()
    {
        var myObject = new MyClass
        {
            Property1 = Session["Property1"].ToString(),
            .....
        };

        return ViewPdf("", "MyPDF", myObject);
    }

where MyPDF is the html page to be rendered.

@model MyProject.ViewModel.MyPdfViewModel

@{
    ViewBag.Title = "Result PDF";
}

<br />
<br />

<div>
<h2 align="center">
<u>Details</u>
</h2>
<div align="justify">
    <p align="justify" style="font-size: 10px">
        Below is the list
    </p>
    <ol style="font-size: 10px">
        <li>First
        </li>

        <li>Second
        </li>

        <li>Third
            <ol type="a">
                <li>3.1
                </li>
                <li>3.2
                </li>
            </ol>
        </li>
        </ol>
        </div>
Deeps
  • 557
  • 9
  • 31

1 Answers1

0

The HTML attribute you are using is flagged as deprecated and you are instead encouraged to use the CSS property list-style-type. Assuming that you are using XMLWorker, you can make that change and it should work as you expect.

<ol style=""font-size: 10px"">
    <li>First</li><li>Second</li>
    <li>Third
        <ol style=""list-style-type: lower-alpha;"">
            <li>3.1</li>
            <li>3.2</li>
        </ol>
    </li>
    <li>Fourth</li>
</ol>
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
  • Thanks Chris. But this doesn't work. the html generated is correct with alpha ordered list, but when it is rendered to PDF, it again gets converted to 1,2,3..... – Deeps Aug 26 '14 at 13:31
  • Using iTextSharp and XMLWorker 5.4.2 my PDF comes through exactly as expected. What versions are you using? – Chris Haas Aug 26 '14 at 13:44
  • I am using iTextSharp 10.0.0.0, but i am not using XMLWorker. Is it required? i am using the PDF reporting in http://www.codeproject.com/Articles/260470/PDF-reporting-using-ASP-NET-MVC. – Deeps Aug 26 '14 at 13:54
  • There is no version of iTextSharp with that version number, the current is 5.5.2 and should only be downloaded from the [official repository](http://sourceforge.net/projects/itextsharp/). You are trying to use `HTMLWorker`, see [this (very long) post](http://stackoverflow.com/a/25164258/231316), specifically the fifth paragraph about `HTMLWorker` and why you should use `XMLWorker`. – Chris Haas Aug 26 '14 at 14:02