Quantcast
Channel: HTML Renderer
Viewing all articles
Browse latest Browse all 693

New Post: CSS not used while rendering an image

$
0
0
Hi,

First of all, thank you so much for this piece of software, it already saved me tons of work!
I have a issue while rendering an image from an html snippet. Below is the code that generates the image.
string barHTML = GetBarHTML(actionID, homepointID, actionScope);
System.Drawing.Image image = HtmlRender.RenderToImage(barHTML);
iTextSharp.text.Image sharpImage = iTextSharp.text.Image.GetInstance(image, System.Drawing.Imaging.ImageFormat.Png);
return sharpImage;
The html that is rendered is valid html and gives me the result in Google Chrome that I'm looking for. However the image that is generated doesn't show any css rendered div's which compose an bar-graph. I've tried to link to an external CSS stylesheet in the html snippet and putting all of the css between <style>-tags but both didn't gave me the result I was hoping to see.

Html snippet:
<html>
  <head>
    <link rel='stylesheet' href='<link to CSS 1>' type='text/cs' />
    <link rel='stylesheet' href='<link to CSS 2>' type='text/cs' />
  </head>
</body>
<div class='action clearfix' style='width:1600px; margin: 0px; padding: 0px; margin-left: 0px;'>
  <div class='actionInfo' style='margin-left: -80px;' >
    <div class='rides'>
      <div class='rideInfo'>
        <strong>
          bar title
        </strong>
        <span style='width: 256px; right:-251px;'>
        </span>
      </div>
    </div>
    <div class='actionGraph' style='width: 800px;'>
        <a class='actionBar begin' href='javascript:void(0);' style='left: 77px;'>
            <span></span>
        </a>
        <a class='actionBar startLimit' href='javascript:void(0);' style='left: 385px;'>
            <span></span>
        </a>
        <a class='actionBar end' href='javascript:void(0);' style='left: 1100px;'>
            <span></span>
        </a>
        <div class='rides'>
            <div class='rideContainer clearfix' style='width: 918px; left: 251px;'>               
                <div class='road begin'></div>
                <div class='road middle' style='width: 898px;'></div>
                <div class='road end'></div>
                <a class='ride begin' href='javascript:void(0);' style='left: -18px;'></a>
                <a class='ride start' href='javascript:void(0);' style='left: -8px;'></a>
                <a class='ride stop' href='javascript:void(0);' style='left: 828px;'></a>
                <a class='ride end' href='javascript:void(0);' style='left: 900px;'></a>
            </div>
        </div>
    </div>
   </div>
</body>
</html>
And the CSS that is inserted
/* action graph */
.action { margin: 15px 0; padding: 15px; border: 0px solid #FFF; margin-left:-50px; }
.actionInfo { float: left; position: relative; width: 15%; }
.rideInfo { position: relative; top: 5px; height: 23px; margin: 20px 0; padding: 0 10px 0 0; text-align: right; }
.rideInfo strong { padding: 0 0 0 5px; }
.rideInfo img { position: relative; top: -3px; }
.rideInfo span { position: absolute; top: 11px; height: 1px; background: #bbb; }
.actionGraph { float: left; position: relative; width: 85%; }
.actionBar { position: absolute; width: 15px; height: 100%; margin: 0 0 0 -7px; }
.actionBar span { display: block; width: 2px; height: 100%; margin: 0 auto; }
.actionBar.begin span { background: #0daf66; }
.actionBar.startLimit span { background: #e2b848; }
.actionBar.end span { background: #d74234; }
.rideContainer { position: relative; margin: 20px 0; }
.road { display: inline-block; float: left; height: 23px; }
.road.begin { width: 10px; background: url("<link to image>"); }
.road.middle { background: url("<link to image>"); }
.road.end { width: 10px; background: url("<link to image>"); }
.ride { display: block; position: absolute; width: 36px; height: 23px; }
.ride.begin { background: url("<link to image>"); }
.ride.end { background: url("<link to image>"); }
.ride.start { background: url("<link to image>"); }
.ride.stop { background: url("<link to image>"); }
Any idea why this might not work?

Viewing all articles
Browse latest Browse all 693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>