0

I am working on an API which generates a pdf document based on an EJS template which then gets emailed to some users. When running Locally everything works as expected however when my API is pushed to heroku the pdf is generated with some odd formatting errors. Its like the page is essentially cut down the middle vertically.

Does anyone know a possible cause of this?

I am using ejs, and html-pdf

Here is the code and template

document generation function

ejs.renderFile(path.join(__dirname, '../views/', "offer.ejs"), {offerData}, (err, data) => {
                if(err)
                    reject(err)
                else
                {
                    const options = {
                        "height": "11.25in",
                        "width": "8.5in",
                        "header": {
                            "height": "10mm"
                        },
                        "footer": {
                            "height": "10mm",
                        }                    
                    };
                    //creates the actual pdf doc for sending
                    pdf.create(data, options).toFile(`./offer_${inqID}.pdf`, function(err, res) {
                        if (err) 
                            reject(err)
                        else
                            resolve(res.filename)                        
                      });    
                }
            });

html pdf template

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Trade-in Disclosure Form</title>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.1/css/bootstrap.min.css" integrity="sha384-VCmXjywReHh4PwowAiWNagnWcLhlEJLA5buUprzK8rxFgeH0kww/aWY76TfkUoSX" crossorigin="anonymous">
    <style>
        body{
            font-family: 'Roboto', sans-serif !important;            
        }
        h1{
            text-decoration: underline !important;
        }
        table.center {
            margin-left:auto; 
            margin-right:auto;
          }
        td.rows{
            padding-bottom: 10px;
            text-align: left !important;
        }
        td.question{
            padding-right: 15px;
        }
        span{
            font-weight:bold !important;                        
        }
    </style>
</head>
<body style="border: solid black 2px; margin-left: 10px; margin-right:10px;">
    <header class="text-center">
        <h1 >The Auto Broker</h1>
        <h2> Trade-In Vehicle Disclosure Form</h2>
        <p style="margin-left: 6em; margin-right: 6em">
            This Form has been filled out by the customer requesting a quote. It contains some basic details to help inform your evaluation of the vehicle.
            If the customer provides false information you have the right to recind or adjust your offer to the customer; otherwise include the value of 
            this vehicle in your total value for the quote. Please ensure to carefully review all the data before providing a quote. Quotes are final and
            cannot be altered once submitted. 
        </p>
    </header>
    <div style="padding-top:20px;">
        <div class="form-container container">
            <div class="row" style="background-color: black;">
                <h3 style="color: aliceblue;" class="ml-2"> Vehicle History</h3>
            </div>
            <table class="center">
                <thead>
                    <tr>
                        <th style="padding-bottom: 20px;"> <h4>Question </h4></th>
                        <th style="padding-bottom: 20px;"> <h4>Response </h4></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td class="rows question">Has the Vehicle been in an accident?</td>
                        <td class="rows"> <%= questionnaire.inaccident %> </td>
                    </tr>
                    <tr>
                        <td class="rows question">Have any panels been repainted, repaired <br> or replaced?</td>
                        <td class="rows"> <%= questionnaire.panelrepairs %> </td>
                    </tr>
                    <tr>
                        <td class="rows question">Are you the original owner?</td>
                        <td class="rows"> <%= questionnaire.originalowner %> </td>
                    </tr>
                    <tr>
                        <td class="rows question">Is this an American Vehicle?</td>
                        <td class="rows"> <%= questionnaire.usvehicle %> </td>
                    </tr>
                    <tr>
                        <td class="rows question">Has the Vehicle been registered in any other <br> Province/State?</td>
                        <td class="rows"> <%= questionnaire.outofprovreg %> </td>
                    </tr>
                    <tr>
                        <td class="rows question">Is the Odometer faulty, replaced or rolled back? </td>
                        <td class="rows"> <%= questionnaire.faultyodometer %> </td>
                    </tr>
                    <tr>
                        <td class="rows question">Does the vehicle have any lights on the dashboard?</td>
                        <td class="rows"> <%= questionnaire.dashlights %> </td>
                    </tr>
                    <tr>
                        <td class="rows question">Does the vehicle have any factory warranty?</td>
                        <td class="rows"> <%= questionnaire.factorywarranty %> </td>
                    </tr>
                    <tr>
                        <td class="rows question">Does the vehicle have extended warranty?</td>
                        <td class="rows"> <%= questionnaire.extwarrenty %> </td>
                    </tr>
                    <tr>
                        <td class="rows question">Was the vehicle ever used as a daily rental,  <br> police vehicle, or taxi/limousine?</td>
                        <td class="rows"> 
                           <% if (questionnaire.rental) { %>
                             Rental <br>
                            <% } %> 
                           
                           <% if (questionnaire.taxilimo) { %>
                            Taxi / Limo <br>
                           <% } %> 
                          
                          <% if (questionnaire.policecar){ %>
                            Police Vehicle <br>
                           <% } %> 
                                        
                         </td>
                    </tr>
                    <tr>
                        <td class="rows question">Does the vehicle require repairs to the following: <br>
                            <span style="margin-left: 10px;">Engine </span> <br> 
                            <span style="margin-left: 10px;">Transmission/Powertrain</span> <br>
                            <span style="margin-left: 10px;">Electrical System </span> <br>
                            <span style="margin-left: 10px;">Air Conditioning System</span>
                        </td>
                        <td class="rows">
                             <%= questionnaire.enginerepair %> <br>
                             <%= questionnaire.transrepair %> <br>
                             <%= questionnaire.electricalrepair %> <br>
                             <%= questionnaire.acrepairs %> <br>
                        </td>
                    </tr>
                    <tr>
                        <td class="rows question">Additional Repair Details</td>
                        <td class="rows"> <%= questionnaire.repairdetails %> </td>
                    </tr>
                    <tr>
                        <td class="rows question">Outstanding Balance</td>
                        <td class="rows"> 
                            <% if (questionnaire.outstandingbalance){ %>
                            <%= questionnaire.outstandingbalance  %>
                           <% } %>  
                        </td>
                    </tr>
                    <tr>
                        <td class="rows question">Total Current Milage</td>
                        <td class="rows"> <%= questionnaire.milage %> K.M </td>
                    </tr>
                    <tr>
                        <td class="rows question">V.I.N</td>
                        <td class="rows"> <%= questionnaire.vin %> </td>
                    </tr>                
                </tbody>
            </table>
        </div>
    </div>
</body>

</html>

Proper Img proper View Broken Img Broken Version

d0rf47
  • 189
  • 9

2 Answers2

0

Was able to solve this issue by adding a single CSS style Rule.

html {
zoom: 0.55;
}

This is most likely required due to the default zoom setting of the html-pdf package. This setting and more can also be configured with options; however, i am unsure if the zoom options can be configured to < 1.

d0rf47
  • 189
  • 9
0

I'm facing the same prblm. I think u have to use inline CSS... u can't use bootstrap. I was facing the same problem. but now it is ok with puppeteer