How does TCPDF specify color to a SVG file? https://tcpdf.org
Mine come out solid black even though other colours are specified in the files and I can not seem to over ride it. Ideally I want to be in a position to dynamically set the color
$pdf->SetTextColor(255,255,255);
$pdf->SetTextColorArray(255,255,255);
$pdf->SetFillColor(255,255,255);
$pdf->SetFillColorArray(255,255,255);
$pdf->SetDrawColor(255,255,255);
$pdf->ImageSVG($file=get_stylesheet_directory_uri().'/images/icon-bath.svg', $x=155, $y=124, $w=10, $h=10, $link='', $align='', $palign='', $border=0, $fitonpage=false);
Following these examples
https://tcpdf.org/examples/example_058/
https://hotexamples.com/examples/-/TCPDF/ImageSVG/php-tcpdf-imagesvg-method-examples.html
Complicated method and slows the generation a fair bit but it works
$svg = get_stylesheet_directory_uri().'/images/icon.svg';
$doc = new DOMDocument;
$doc->load($svg);
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('svg', 'http://www.w3.org/2000/svg');
$path_list = $xpath->query('svg:path');
$circle_list = $xpath->query('svg:circle');
foreach ($path_list as $path) {
$path->setAttribute('fill', '#FFFFFF');
}
foreach ($circle_list as $circle) {
$circle->setAttribute('fill', '#FFFFFF');
}
$svgString = $doc->saveXML();
$pdf->ImageSVG('@' . $svgString, $x=130, $y=124, $w=10, $h=10, $link='', $align='', $palign='', $border=0, $fitonpage=false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With