java - PDF not getting generated when using iText API with CSS -


i trying generate pdf html having css.

below code snippet

        document document = new document();         pdfwriter pdfwriter = pdfwriter.getinstance(document, new fileoutputstream(outfilename));          document.open();          string htmltxt = fileutils.readfiletostring(new file(dirpath + inpfilename), "utf-8");         bytearrayinputstream fis = new bytearrayinputstream(htmltxt.getbytes("utf-8"));         xmlworkerhelper worker = xmlworkerhelper.getinstance();         // worker.parsexhtml(pdfwriter, document, fis);          worker.parsexhtml(pdfwriter, document, new fileinputstream(dirpath + inpfilename),                 new fileinputstream(css));          // close document         document.close();         // close writer         pdfwriter.close(); 

i tried generating pdf using worker.parsexhtml(pdfwriter, document, fis); pdf gets generated without

which worked fine used worker.parsexhtml(pdfwriter, document, new fileinputstream(dirpath + inpfilename), new fileinputstream(css)); in case pdf gets generated without content .

i tried how use css resolver suggested in itext parse html css example

important note -- html has been generated jtidy api. here html , css file

#pdfpreview { font-family: arial }    #pdfpreview .page_1 {position:relative; overflow: hidden;padding: 0px;border: none;width: 90%;margin:0 auto;}  #pdfpreview .page_1 .id_1 {border:none;margin: 0px 0px 0px 0px;padding: 0px;border:none;width: 100%;overflow: hidden;}  #pdfpreview .page_1 .id_2 {border:none;margin: 107px 0px 0px 8px;padding: 0px;border:none;width: 720px;overflow: hidden;}    #pdfpreview .page_1 #dimg1 {position:absolute;top:181px;left:0px;z-index:-1;width:736px;height:677px;}  #pdfpreview .page_1 #dimg1 #img1 {width:736px;height:677px;}    #pdfpreview .page_1 #inl_img1 {position:relative;width:7px;height:17px;}        #pdfpreview #page_2 {position:relative; overflow: hidden;margin: 41px 0px 37px 40px;padding: 0px;border: none;width: 776px;}  #pdfpreview #page_2 #pdfpreview .id_1 {border:none;margin: 0px 0px 0px 0px;padding: 0px;border:none;width: 776px;overflow: hidden;}  #pdfpreview #page_2 .id_2 {border:none;margin: 28px 0px 0px 8px;padding: 0px;border:none;width: 720px;overflow: hidden;}    #pdfpreview #page_2 #dimg1 {position:absolute;top:7px;left:0px;z-index:-1;width:741px;height:935px;}  #pdfpreview #page_2 #dimg1 #img1 {width:741px;height:935px;}    #pdfpreview .vehicledescriptiontable{      border: black 1px solid;  }    #pdfpreview .vehicledescriptiontable table tr td:nth-child(1){  	width: 3%;      padding-left: 1%;  }    #pdfpreview .vehicledescriptiontable table tr td:nth-child(2){  	    width: 57%;  }    #pdfpreview .vehicledescriptiontable table tr td:nth-child(3){  	    width: 3%;      padding-left: 1%;  }    #pdfpreview .vehicledescriptiontable table tr td:nth-child(4){  	    width: 37%;  }    #pdfpreview td{  	vertical-align: top;  }    #pdfpreview tr{  	/* line-height: 0em; */  }    #pdfpreview html {      font:  13px 'arial';  }    #pdfpreview p.sectionhead {      text-align: center;      font: 16px 'arial' bold;      background-color: #ccc;      height: 2em;      padding-top: .5em;      margin-bottom: 0;      border-top: black 1px solid;      border-left: black 1px solid;      border-right: black 1px solid;      /* width: 774px; */  }    #pdfpreview p.subsectionhead {      font-size: 14px;      font-weight: bold;      background-color: #eee;      margin-top: 0;      height: 1.5em;      padding-left: 2%;      padding-top: .2em;      margin-bottom: 0;      border-top: 1px solid black;      border-bottom: 1px solid black;      /* border-bottom: none; */      /* border-right: black 1px solid; */      /* width: 100%; */  }    #pdfpreview table {      /* border: 1px solid black; */      border-bottom: 4em;      width: 100%;  }    #pdfpreview td:nth-child(3) {      border-left: black 1px solid;  }    #pdfpreview tbody {      border-bottom: black 1px solid;      /* padding-bottom: 1em; */  }    #pdfpreview p {      margin-top: 0;      margin-bottom: .2em;  }    #pdfpreview .floatright{  	float: right;  	text-align: right;  }    #pdfpreview .floatleft{  	float:left;  	text-align: left;  }    #pdfpreview .topmargin{  	margin-top:.4em;  }    /*melissa page2*/  #pdfpreview #page2, #vehiclelisttable, #table3 {    width: 90%;    margin: 0 auto;    border-spacing: 0px;  }  #pdfpreview #page2 thead {    background-color: #eee;  }  #pdfpreview #page2 thead th:first-child {    padding-bottom: 2rem;    text-align: left;  }  #page2 thead th:nth-child(2) {    padding-bottom: 2rem;    text-align: right;  }  #pdfpreview #page2 tbody .simple td {    font-weight: bold;  }  #pdfpreview #page2 tbody .simple td p {    font-weight: normal;  }  #pdfpreview #page2 tbody .header {    width: 15%;    padding: .3rem;    background-color: #eee;    font-weight: bold;  }  #pdfpreview #page2 tbody .subheader {    width: 10%;    padding: .3rem;  }  #pdfpreview #page2 tbody .subtableheader {    text-align: center;  }  #pdfpreview #page2 tbody .fillout {    padding: .3rem;    text-align: center;    color: #e6e6e6;  }  #pdfpreview #page2 tbody .filledout {    padding: .3rem;    text-align: center;    color: black;  }  #page2 tbody .bottomrow {    padding-bottom: 6rem;    text-align: left;  }    #pdfpreview .border-top {    border: 1px solid black;  }  #pdfpreview .border-top-left{  	border-left: 1px solid black;  	border-top: 1px solid black;  	border-bottom: 1px solid black;  }  #pdfpreview .border-middle-left {    border-left: 1px solid black;    border-right: 1px solid black;    border-bottom: 1px solid black;  }  #pdfpreview .border-middle-fix{  	border-bottom: 1px solid black;  }  #pdfpreview .border-middle {    border-right: 1px solid black;    border-bottom: 1px solid black;  }  #pdfpreview .bottom-left {    border-left: 1px solid black;    border-bottom: 1px solid black;  }  #pdfpreview .bottom-right {    border-right: 1px solid black;    border-left: 1px solid black;    border-bottom: 1px solid black;  }    #pdfpreview .footer1{  	margin-bottom:4em;  }    #pdfpreview td.topmargin{  	width:50%;  }    #pdfpreview .footerclass{  	width:90%;  	margin:0 auto;  	padding-bottom:4em;  }    #pdfpreview .mainbodyheadarea{  	border-left:1px solid black;  	border-right:1px solid black;  	border-top:1px solid black;  }    #pdfpreview .submissioncellleft{  	width:50%;  	padding:1em;  }    #pdfpreview .submissioncellright{  	width: 50%;  	padding:1em;  	border-left: 1px solid black;  }    #pdfpreview td.addresscity {      width: 40%;  }    #pdfpreview td.addresszip {      width: 20%;  }    #pdfpreview td.addressstate {      width: 20%;  }    #pdfpreview td.addresscountry {      width: 20%;      border-left:none;  }    #pdfpreview table{  	border-spacing: 0;  }    #pdfpreview .addressrow{  	padding: 0;  }    #pdfpreview #vehiclelisttable th, #pdfpreview #vehiclelisttable td {  	padding:.5em;  	font-weight: bold;  }    #pdfpreview .filloutheight{  	height:1em;  }    #pdfpreview .borderleft{  	border-left:1px solid black;  }    #pdfpreview .filladdresscity,.filladdressstate,.filladdresscountry,.filladdresszip{  	margin-left: 3em;  }    #pdfpreview .center{  	text-align: center;  }    #pdfpreview #vehiclelisttable, #pdfpreview #table3 {  	width:90%;  	margin:0 auto;  }    #pdfpreview  td {  	padding:.5em;  }          #pdfpreview {      width: 800px;  }    #pdfpreview p, td{    font-size:12px;  }
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"  "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">  <?xml-stylesheet href="foo.css" media="all" type="text/css"?>  <html xmlns="http://www.w3.org/1999/xhtml">  <head>  <meta name="generator"  content="html tidy java (vers. 2009-12-01), see jtidy.sourceforge.net" />  <meta charset="utf-8" />  <title>pdf html title</title>  <link rel="stylesheet" type="text/css" href="previewstylespdf.css" />  </head>  <body>  <div id="pdfpreview">  <table id="page2">  <thead>  <tr>  <th colspan="2" class="border-top-left">table title</th>  <th colspan="6" class="border-top">author name</th>  </tr>  </thead>  <tbody>  <tr class="simple">  <td colspan="8" class="border-middle-left">single or multiple  vehicle registration single customer</td>  </tr>  <tr class="simple">  <td colspan="8" class="border-middle-left">  <p>instructions members only: scan , upload  completed , <b><ins style="font-weight: bold">signed</ins> form  mail-id <a  href="#">myname@company.com</a></b></p>  </td>  </tr>  <tr>  <td class="header border-middle-left">dealer</td>  <td class="subheader border-middle-fix">dealer name</td>  <td colspan="4" class="border-middle filldealername filledout">  mercedez</td>  <td class="subheader border-middle">phone</td>  <td colspan="2" class="border-middle filldealerphone filledout">  (###)###-####</td>  </tr>  <tr>  <td class="subheader border-middle-left">name dealer code</td>  <td class="border-middle-fix filldealercode filledout">borderland</td>  <td class="subheader border-middle">dealer contact name</td>  <td colspan="3" class="border-middle filldealercontact filledout">  </td>  <td class="subheader border-middle">email</td>  <td class="border-middle filldealeremail filledout"></td>  </tr>  </tbody>  </table>  <table id="vehiclelisttable">  <thead>  <tr>  <th class="header border-middle-left">serial number</th>  <th colspan="4" class="subtableheader border-middle-fix">col title #1</th>  <th colspan="2" class="subtableheader border-middle borderleft">col title #2</th>  <th colspan="2" class="subtableheader border-middle">col title #3</th>  </tr>  </thead>  <tbody>    <tr class="filloutheight">  <td class="fillout border-middle-left filloutheight"></td>  <td class="fillout border-middle-fix filloutheight" colspan="4">  </td>  <td class="fillout border-middle filloutheight" colspan="2"></td>  <td class="fillout border-middle filloutheight" colspan="2"></td>  </tr>    <tr class="filloutheight">  <td class="fillout border-middle-left filloutheight"></td>  <td class="fillout border-middle-fix filloutheight" colspan="4">  </td>  <td class="fillout border-middle filloutheight" colspan="2"></td>  <td class="fillout border-middle filloutheight" colspan="2"></td>  </tr>  </tbody>  </table>  <table id="table3">  <tbody>  <tr>  <td class="header border-middle-left">customer</td>  <td class="subheader border-middle-fix">name</td>  <td colspan="3" class="border-middle fillcustomername filledout">  atlantis city</td>  <td class="subheader border-middle">phone</td>  <td colspan="2" class="fillout border-middle">phone</td>  </tr>  <tr>  <td class="subheader border-middle-left" colspan="2">authorized  representative name</td>  <td class="fillout border-middle" colspan="6">name</td>  </tr>  <tr>  <td class="subheader border-middle-left">email</td>  <td class="fillout border-middle" colspan="7">email</td>  </tr>  <tr>  <td class="subheader border-middle-left">address</td>  <td class="border-middle filladdress1 filledout" colspan="7">street address</td>  </tr>  <tr>  <td colspan="8" class="addressrow">  <table>  <tbody>  <tr>  <td class="subheader border-middle-left addresscity">city <span  class="filladdresscity filledout">atlantis</span></td>  <td class="subheader border-middle addressstate">state/province  <span class="filladdressstate filledout">ee</span></td>  <td class="subheader border-middle addresscountry">country</td>  <td class="subheader border-middle addresszip">zip/postal code  <span class="filladdresszip filledout">99999</span></td>  </tr>  </tbody>  </table>  </td>  </tr>  <tr>  <td colspan="4" class="subheader border-middle-left">the above  vehicles used following vocation / applications  only:</td>  <td class="fillout border-middle" colspan="4">vocation</td>  </tr>  <tr class="simple">  <td colspan="8" class="border-middle-left">  <p><b>customer certification:</b> information go here.</p>  </td>  </tr>  <tr>  <td colspan="4" class="subheader bottomrow bottom-left">customer  authorized customer representative signature (required)</td>  <td colspan="4" class="subheader bottomrow bottom-right">date</td>  </tr>  </tbody>  </table>  <div class="footerclass">  <div class="floatleft topmargin">  <p class="">pdf (rev: 4/2/2014)</p>  </div>  <div class="floatright topmargin">  <p class="">page 2 of 2</p>  </div>  </div>  </div>  </body>  </html>


Comments