Afur / flutter_html_to_pdf

Flutter plugin for generating PDF files from HTML
MIT License
69 stars 126 forks source link

Not showing dynamic data in PDF #39

Closed NiroopNife closed 3 years ago

NiroopNife commented 3 years ago

I'm fetching dynamic data from the SQF and trying to show that in the PDF but noting shows up. I'm still getting the data untill showing it in the PDF but when i tried to inculde the variable in the PDF it does'nt show anything.

Future<void> generateExampleDocument() async {
    var htmlContent = """
 <!DOCTYPE html>
    <html>
    <head>
    <style>
    h2 {text-align: center;}
      headerParagh {text-align: center;}
      .row {display: flex;}
      .headerColumn1 {
          flex: 30%;
          padding: 10px;
      }
      .headerColumn2 {flex: 60%;}
      .headerColumn3 {
          flex: 10%;
          padding: 10px;
      }
      .facilityColumn {
          flex: 50%;
          padding 10px;
      }
      .deliveryColumn {
          flex: 50%;
          padding 10px;
      }
     </style>
    </head>
    <body>
    <table style="width:100%">         
      <tr style="background-color:#E8E8E8">
          <th>SERIAL</th>
          <th>ARTICLE NUMBER</th>
          <th>ADDRESSEE NAME</th>
          <th>REMARK</th>
          <th>SIGNATURE</th>
        </tr>
        <tr>
          <td>1</td>
          <td>
            <img src="https://www.freepnglogos.com/uploads/barcode-png/barcode-laser-code-vector-graphic-pixabay-3.png", width=100/><br />
        RK9876543210IN
          </td>
          <td></td>
          <td>
          <p>ADDRESSEE CANNOT BE LOCATED</p>
          10-02-2021 14:24:42
          </td>
          <td></td>
        </tr>
        <tr>
          <td>2</td>
          <td style="vertical-align: middle">
            <img src="data:image/png;base64,$base64Str" alt="Red dot"><br />
        RK0123456789IN
          </td>
          <td>$dummyName</td>
          <td><p>DELIVERED</p></td>
          <td>
             <img src="https://upload.wikimedia.org/wikipedia/en/3/38/Jimmy_warshawsky_signature.png", width=100px/>
          </td>
         </tr>
    </table>
    </body>
    </html>
    """;
   Directory appDocDir = await getApplicationDocumentsDirectory();
    var targetPath = appDocDir.path;
    var targetFileName = "example-pdf";
    var generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlContent(
        htmlContent, targetPath, targetFileName);
    generatedPdfFilePath = generatedPdfFile.path;
}

The dynamic data which I'm getting from the database are stored in base64Str & dummyName.

The dummyName is a text which I'm retreiving from the database abd the base64Str is an image. Both the values are being retrived untill it is shown in the PDF file.