Menu

Remote SVG via cURL Fed to ImageSVG Not Working

Help
Michael
2014-09-13
2014-09-15
  • Michael

    Michael - 2014-09-13

    Hi, I'm trying to load a few SVGs remotely and feed them into my PDF. I know the .svg files are loading correctly because if I print the cURL result I see them and when I copy/paste the <svg> code directly it works. However, when I try to load via cURL and then feed to ImageSVG I get the following error:
    TCPDF ERROR: SVG file not found: @

    Here's the code I'm using:

    1
    2
    3
    4
    5
    6
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $svg_data = curl_exec($ch);
    $pdf->ImageSVG($file = '@'.$svg_data, $x=15, $y=30, $w='', $h='');
    

    Thanks so much for any help!

     
  • Simon

    Simon - 2014-09-13

    Does it work with file_get_contents() rather than curl?

    Do you need it to keep a cookie jar to work?

     
  • Michael

    Michael - 2014-09-13

    Hmm, no dice with file_get_contents, same error. I don't think I need any kind of cookies because if instead of calling ImageSVG on the last line I do something like print_r($svg_data) the SVG files show in the browser i.e. their data is output correctly.

     
  • Simon

    Simon - 2014-09-13

    Is it a public url I can try?

     
  • Simon

    Simon - 2014-09-14

    Hmm. Don't know what to say. It worked for me using file_get_contents.

     
  • Michael

    Michael - 2014-09-15

    Turns out you're right, it works with cURL too, it was a silly error I hadn't noticed but you telling me it does indeed work helped me figure it out.

    Thanks for your help!

     

Log in to post a comment.