PdfAWriter does not convert unordered lists and tables

I'm having trouble using a class PdfAWriter

to convert my HTML to PDF, the HTML converts fine until it finds a table or list.

If I use the class PdfWriter

it works fine, but I need the PDF / A version.

Here is the code I am using to convert:

public static byte[] ConverterParaPdf(string html)
{
    MemoryStream ms = new MemoryStream();
    Document document = new iTextSharp.text.Document(PageSize.A4);
    PdfAWriter writer = PdfAWriter.GetInstance(document, ms, PdfAConformanceLevel.PDF_A_1B);
    //PdfWriter writer = PdfWriter.GetInstance(document, ms);
    writer.PdfVersion = PdfWriter.VERSION_1_7;
    writer.SetTagged();
    writer.ViewerPreferences = PdfWriter.DisplayDocTitle;
    writer.CloseStream = false;
    writer.InitialLeading = 12.5f;
    writer.CompressionLevel = PdfStream.BEST_COMPRESSION;
    //writer.SetFullCompression(); //Causa erro no padrão PDF_A_1*

    try
    {
        document.AddLanguage("pt-BR");
        document.AddCreationDate();
        writer.CreateXmpMetadata();
        document.Open();
        ICC_Profile icc = ICC_Profile.GetInstance((byte[])Properties.Mensagens.ResourceManager.GetObject("icc_profile"));
        writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

        MemoryStream cssStream = new MemoryStream(Encoding.UTF8.GetBytes("html, html * { font-family: Arial, Arial, Arial!important; color: black!important; }"));
        MemoryStream htmlStream = new MemoryStream(Encoding.UTF8.GetBytes(html));
        XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, htmlStream, cssStream);
        document.Close();
        writer.Close();
    }
    catch (Exception ex)
    {
        throw ex;
    }
    byte[] byteArray = ms.ToArray();
    ms.Close();

    return byteArray;
}



<!DOCTYPE html>
<html>
    <head>
    <title></title>
    <style type="text/css">
        .container {
            font-family: Arial;
            font-size: 15px;
            background-color: white;
            margin: 20px;
        }

        .imagem {
            padding-bottom: 15px;
        }

        .titulo {
            font-size: 23px;
            font-weight: bold;
        }

        .barra-tipo-documento {
            background-color: #3B454E;
            width: 4px;
            height: 40px;
            float: left;
        }

        .tipo-documento {
            padding-left: 16px;
            padding-top: 13px;
            float: left;
            font-size: 17px;
            color: #3B454E;
            font-weight: bold;
        }
    </style>
    </head>

    <body>
        <div class="container">
            <table>
                <tr>
                     <td class="imagem">
                            <img src="http://localhost:8090/Resources/img/logomarca-documentos.wmf" height="45" alt="TCE-ES"/>
                     </td>
                </tr>
            <tr>
                <td>
                    <div class="barra-tipo-documento">&nbsp;</div>
                    <div class="tipo-documento">Comunicação Interna</div>
                </td>
            </tr>
            </table>
            <br />
            <br />

            <div><strong>N.º: </strong>00747/2014-7</div>
            <div><strong>Data: </strong>22/10/2014 18:05:10</div>
            <div><strong>Assunto: </strong>teste</div>
            <div><strong>De: </strong>NCD</div>           
            <div><strong>Para: </strong>NCD</div>
            <div></div>
            <div><strong>Anexos: </strong>12252/2014-9, 12253/2014-3</div>

            <br />

            <div><p>&nbsp;gerqg r</p>

<p>g&nbsp;</p>

<ol>
    <li>eqrg geqr</li>
    <li>g er</li>
    <li>g</li>
    <li>qe r</li>
    <li>geqr</li>
</ol>

<p>g eqrgqergqerg</p>

<p>&nbsp;geqr geqrg</p>
</div>
        </div>
    </body>
</html>

      

Image: http://postimg.org/image/9utepiza1/

I am using itextsharp / itextsharp.pdfa / itextsharp.xmlworker / itextsharp.xtra version 5.5.3.0.

If there is another way to do it please tell me I even tried to use HtmlWorker

which is deprecated.

+3


source to share





All Articles