1
votes

I'm using itextsharp to create a pdf file from html. It's work great, but i have problems with style attributes inside HTML. To parse html i'm using this code.

cssResolver.AddCssFile(AppDomain.CurrentDomain.BaseDirectory+"/Content/css/style.css",true);
                    IPipeline pipeline =
                     new CssResolverPipeline(cssResolver,
                      new HtmlPipeline(htmlContext,
                        new PdfWriterPipeline(doc, writer)));

                    var worker = new XMLWorker(pipeline, true);
                    var p = new XMLParser(true, worker, Encoding.Unicode);

                    using (var sr = new StringReader(html))
                    {
                        p.Parse(sr);
                    }

So it's apply my css styles and they works, but i have some style in my html file, i can't move it to css file because they formed dynamically.

<div id="VC" class="vc-scene-canvas-div" style="left: 15px; bottom: 15px; height: 517px; width: 244px;">
   <img src="">                          
   <img src="" style="left: 32px; bottom: 0px; height: 459px; width: 181px; z-index: 10;">
   <img src="" style="left: 14px; bottom: 0px; height: 477px; width: 217px; z-index: 20;">                                               
</div>

And when i formed my pdf i see all except images.But when i remove style tags all OK. Is it possible to use style in css and html at the same time? Maybe i'm doing something wrong?

1

1 Answers

1
votes

Your problem is the CSS attribute you are using, XMLWorker doesn't support left, bottom, z-index, only partially height

You can check the support of every CSS attribute from this list