jeudi 10 août 2017

Inline CSS is not working with gem 'htmltopdf'

My requirement is to download docx file and should be open on Microsoft word: I am using below given gems:

gem 'responders' gem 'htmltoword

Find Controller Code from the below:

require 'htmltoword'

class Admin::VisibilitiesController < ApplicationController respond_to :docx, :html, :css,:js

def preview
     @project = Project.find_by(id: params[:id])
     @feeder = Project.find_by(id: params[:id]).form2.last.feeder11s.first
      respond_to do |format|
        format.docx do
        render :docx => "report1_docx",:template => 'admin/visibilities/preview.html.docx.erb', :page_height => 600, :page_width =>345
      end
    end
  end

view file code

<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<style type="text/css">
  div.alwaysbreak { page-break-before: always; }
div.nobreak:before { clear:both; }
div.nobreak { page-break-inside: avoid; }
td{padding: 2px 5px;}

</style>
<div style="padding-top:20px;">



<table style="width:800px;margin:0px auto;border:1px solid grey; background: #fff;margin: 0 auto;margin-bottom:30px;padding:10px 20px; ">      
       <tbody>
        <tr>
          <td style="padding: 15px 0 50px;">
            <table style="padding:0px;overflow:hidden;display:table;">
              <tbody>
                <tr>
                  <td style="font-size: 16px;width:100%;font-weight:600">
                    Report No......./...../......./20116-17.....
                  </td>         
                </tr>
                <tr>

                  <td style="font-size: 16px;width:100%;font-weight:600">
                    Dated: ......

                  </td>

                </tr>
              </tbody>  
            </table>
          </td>
        </tr>



        <tr>
         <td style="font-size:28px;font-weight:bold;text-align:center;padding-bottom:20px; font-style: italic;">THIRD PARTY VILLAGE INSPECTION REPORT</td>
        </tr> 
          <tr>
         <td style="font-size:28px;font-weight: bold;text-align:center;padding-bottom:25px; font-style: italic;">OF</td>
        </tr> 
             <tr>
         <td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:25px;">RURAL ELECTRIFICATION WORKS UNDER DEEN DAYAL UPADHYAYA GRAM JYOTI YOJANA (erstwhile RGGVY 12TH PLAN)</td>
        </tr> 
        <tr>
         <td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:20px;">IN</td>
        </tr> 
        <tr>
         <td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:25px;">..............DISTRICT</td>
        </tr> 
        <tr>
         <td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:20px;">SUBMITTED TO</td>
        </tr>     
        <tr>
         <td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:25px;">........................</td>
        </tr>           
        <tr>
           <td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:20px;">SUBMITTED BY </td>
        </tr> 
               <tr>
         <td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:30px;">........................</td>
        </tr>
        <tr>
          <td style="font-style: italic; padding-bottom: 30px; padding-top: 100px;">
            <table style="width: 100%; margin-top: 50px;">
              <tr>
                <td style="font-size:12px;padding-bottom:10px;font-weight:600">Report No (admin)/District(survey)/1st/2016-17/070</td>
                <td style="font-size:12px;padding-bottom:10px;font-weight:600; text-align: right;">Dated: from survey (form1)</td>   
               </tr>
            </table>
          </td>
        </tr>        
        <tr>
          <td style="padding-bottom: 50px;">
            <table style="width: 100%;">
              <tr>
                <td style="font-size:18px;font-weight:600">Location:</td>
                </tr> 
                 <tr>
                 <td style="font-size:16px;font-weight:600">Name of Village     :  <%= @project.form1.try(:village_name) %></td>
                 <tr>
                 <td style="font-size:16px;font-weight:600">Census Code No     :                        <%= @project.form1.try(:census_code_no) %>
</td>
                </tr>

                <tr>
                 <td style="font-size:16px;font-weight:600">Name of Block       : <%= @project.form1.try(:block_name) %></td>
                </tr>
            </table>
          </td>
        </tr>


          </tbody>

    </table>
</body>

</html>

OutPut

enter image description here

Aucun commentaire:

Enregistrer un commentaire