TCPDF Specifying SVG Fill Color
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
svg pdf-generation tcpdf
add a comment |
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
svg pdf-generation tcpdf
Found a setSVGStyles but unsure how to use it tcpdf.org/docs/srcdoc/TCPDF/class-TCPDF/#_setSVGStyles
– Dwayne
Dec 31 '18 at 1:58
add a comment |
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
svg pdf-generation tcpdf
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
svg pdf-generation tcpdf
svg pdf-generation tcpdf
asked Dec 30 '18 at 23:14


DwayneDwayne
63
63
Found a setSVGStyles but unsure how to use it tcpdf.org/docs/srcdoc/TCPDF/class-TCPDF/#_setSVGStyles
– Dwayne
Dec 31 '18 at 1:58
add a comment |
Found a setSVGStyles but unsure how to use it tcpdf.org/docs/srcdoc/TCPDF/class-TCPDF/#_setSVGStyles
– Dwayne
Dec 31 '18 at 1:58
Found a setSVGStyles but unsure how to use it tcpdf.org/docs/srcdoc/TCPDF/class-TCPDF/#_setSVGStyles
– Dwayne
Dec 31 '18 at 1:58
Found a setSVGStyles but unsure how to use it tcpdf.org/docs/srcdoc/TCPDF/class-TCPDF/#_setSVGStyles
– Dwayne
Dec 31 '18 at 1:58
add a comment |
2 Answers
2
active
oldest
votes
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);
add a comment |
Improved logic to handle multiple SVG files
function getModifiedSvgString($svg, $color) {
$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', $color);
}
foreach ($circle_list as $circle) {
$circle->setAttribute('fill', $color);
}
return $doc->saveXML();
}
// Icon 1
$svg = get_stylesheet_directory_uri() . '/images/icon-1.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 130, $y = 124, $w = 10, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
// Icon 2
$svg = get_stylesheet_directory_uri() . '/images/icon-2.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 155, $y = 124, $w = 10, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
// Icon 3
$svg = get_stylesheet_directory_uri() . '/images/icon-3.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 178, $y = 124, $w = 18, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53982203%2ftcpdf-specifying-svg-fill-color%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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);
add a comment |
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);
add a comment |
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);
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);
answered Jan 1 at 7:09


DwayneDwayne
63
63
add a comment |
add a comment |
Improved logic to handle multiple SVG files
function getModifiedSvgString($svg, $color) {
$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', $color);
}
foreach ($circle_list as $circle) {
$circle->setAttribute('fill', $color);
}
return $doc->saveXML();
}
// Icon 1
$svg = get_stylesheet_directory_uri() . '/images/icon-1.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 130, $y = 124, $w = 10, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
// Icon 2
$svg = get_stylesheet_directory_uri() . '/images/icon-2.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 155, $y = 124, $w = 10, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
// Icon 3
$svg = get_stylesheet_directory_uri() . '/images/icon-3.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 178, $y = 124, $w = 18, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
add a comment |
Improved logic to handle multiple SVG files
function getModifiedSvgString($svg, $color) {
$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', $color);
}
foreach ($circle_list as $circle) {
$circle->setAttribute('fill', $color);
}
return $doc->saveXML();
}
// Icon 1
$svg = get_stylesheet_directory_uri() . '/images/icon-1.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 130, $y = 124, $w = 10, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
// Icon 2
$svg = get_stylesheet_directory_uri() . '/images/icon-2.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 155, $y = 124, $w = 10, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
// Icon 3
$svg = get_stylesheet_directory_uri() . '/images/icon-3.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 178, $y = 124, $w = 18, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
add a comment |
Improved logic to handle multiple SVG files
function getModifiedSvgString($svg, $color) {
$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', $color);
}
foreach ($circle_list as $circle) {
$circle->setAttribute('fill', $color);
}
return $doc->saveXML();
}
// Icon 1
$svg = get_stylesheet_directory_uri() . '/images/icon-1.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 130, $y = 124, $w = 10, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
// Icon 2
$svg = get_stylesheet_directory_uri() . '/images/icon-2.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 155, $y = 124, $w = 10, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
// Icon 3
$svg = get_stylesheet_directory_uri() . '/images/icon-3.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 178, $y = 124, $w = 18, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
Improved logic to handle multiple SVG files
function getModifiedSvgString($svg, $color) {
$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', $color);
}
foreach ($circle_list as $circle) {
$circle->setAttribute('fill', $color);
}
return $doc->saveXML();
}
// Icon 1
$svg = get_stylesheet_directory_uri() . '/images/icon-1.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 130, $y = 124, $w = 10, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
// Icon 2
$svg = get_stylesheet_directory_uri() . '/images/icon-2.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 155, $y = 124, $w = 10, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
// Icon 3
$svg = get_stylesheet_directory_uri() . '/images/icon-3.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 178, $y = 124, $w = 18, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);
answered Jan 1 at 8:06


DwayneDwayne
63
63
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53982203%2ftcpdf-specifying-svg-fill-color%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Found a setSVGStyles but unsure how to use it tcpdf.org/docs/srcdoc/TCPDF/class-TCPDF/#_setSVGStyles
– Dwayne
Dec 31 '18 at 1:58