Forum


Replies: 3   Views: 127
Insert svg file in html

Posted by fairshareitservices  · 06-01-2025 - 08:21

 we are generating word doument using HTML template . need svg image instead of jpg file . But below code is not showing svg file. 

foreach ($result as $row) {
                        # Add each row data into the array in the desired format
                        $fundsData[] = [
                                $row['scheme_name'],  # Scheme name
                                $row['benchmark'],  # Benchmark
                                $row['product_labelling'],  # product labelling
                                $row['benchmark_risk_image'],
                                $row['scheme_risk_image'] # Full path for benchmark risk image
                        ];
                }
                $rows = generateRows($fundsData,$col_count);
                $BenchmarkTableHtml = str_replace('$rowsPlaceholderNoPrc$', $rows, $BenchmarkTableWith4ColsHtml);
                $currentBenchmarkTableWithoutPRCRowHtml = $BenchmarkTableHtml;
                #End without prc image code 
                
                $fileName = 'benchmark_riskometer_BENCHMARKMF';
                
                //get footer date details from tag definition file. 
                //Get Mapping table columns and row index of scheme code
                $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();

                $mappingSpreadsheet = $reader->load("$INPUT_DIRECTORY/scheme_tag_definition.xlsx");

                $mappingSpreadsheetData=$mappingSpreadsheet->getActiveSheet()->toArray();

                # code to actual generate doc file. 
                        if($templateType == 'MF'){
                                        $template_benchmark_file_name = 'benchmark_riskometer_template';
                                        mLog("Generate -> $OUTPUT_DIRECTORY/$fileName");
                                        $docx = new CreateDocxFromTemplate("$INPUT_DIRECTORY/$template_benchmark_file_name".'.docx');
                                        
                                        //replace footer date 
                                        $variableDetails = getDetailsOfTheVariableFromMappingTable('footer_date', $mappingSpreadsheetData);
                                        
                                        $_SESSION['session_placeholder_name'] = 'footer_date';
                                        $docx = replacePlaceHolderByText('footer','NOCODE', $docx,$variableDetails,'');
                                                                   
                                        //replace footer logo
                                        $variableDetails = getDetailsOfTheVariableFromMappingTable('mf_footer_logo', $mappingSpreadsheetData);
                                        
                                        $_SESSION['session_placeholder_name'] = 'mf_footer_logo';
                                        $docx = replacePlaceHolderByImage('footer','NOCODE', $docx,$variableDetails,'');
                        
                                        $docx->replaceVariableByHTML("benchmark_table_prc", 'block', $currentBenchmarkTableRowHtml, array('customListStyles' => true, 'isFile' => false, 'parseDivsAsPs' => true, 'downloadImages' => false));
                                        $docx->replaceVariableByHTML("benchmark_table", 'block', $currentBenchmarkTableWithoutPRCRowHtml, array('customListStyles' => true, 'isFile' => false, 'parseDivsAsPs' => true, 'downloadImages' => false));
                                        $docx->createDocx("$OUTPUT_DIRECTORY/$fileName");
                                
                        }


# Generate rows dynamically
function generateRows($data,$col_count) {
    //print_r($data);die();
    
    $rowsHtml = '
    <style>td {border:0.8px solid #000000; text-align:left; vertical-align:middle;}</style>';


    foreach ($data as $fund) {
        $rowsHtml .= '<tr style="border:0.8px solid #000000;height:110px;">';
        
        # First column contains an image for benchmark
        $rowsHtml .= '<td style="text-align:left;font-size:10px;vertical-align: top;"><span style="font-size:12px;color:#0C4C8F">'.$fund[0].'</span><br><span><b>BENCHMARK : </b></span><span style="font-size:9px;">'.$fund[1].'</span>
        </td>';
        
        # Second column contains text for the scheme name
        $rowsHtml .= '<td text-align:left;vertical-align: top;>' . $fund[2] . '</td>';
        
        # Third column contains an image for the riskometer
        $rowsHtml .= '<td style="font-size:8px;"><span>.</span><img type="image/svg+xml" style="display: block; margin: 0 auto;" src="https://devfactsheet.atilagu.com/benchmark_images/' . $fund[3] . '" alt="Riskometer Image" width="300" height="165"></td>';
        
        $rowsHtml .= '<td style="font-size:8px;"><span>.</span><img type="image/svg+xml" style="display:block; margin:0 auto;" src="https://devfactsheet.atilagu.com/benchmark_images/' . $fund[4] . '" alt="Benchmark Image" width="300" height="165"></td>';
        
         if($col_count == 5){
        # Fourth column contains an image for potential risk class
        $rowsHtml .= '<td style="font-size:8px;"><span>.</span></br></br><img style="display: block; margin: 0 auto;" src="https://devfactsheet.atilagu.com/benchmark_images/' . $fund[5] . '" alt="Potential Risk Class Image" width="250" height="130"></td>';
        }
        $rowsHtml .= '</tr>';
    }

    return $rowsHtml;
}Â