Announcement

Collapse
No announcement yet.

SVG support inconsistency between entry points and SVG not supported by TCPDF

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SVG support inconsistency between entry points and SVG not supported by TCPDF

    I tried to insert and SVG image in a template using the template editor and received a 403 (forbidden) message.

    Checking the Attachment entry point class, which is used to upload inline images in templates, I noticed that the type "image/svg+xml" is not included in the protected attribute $allowedFileTypes, thus the 403 error.

    However the file was uploaded to the data/upload directory and recorded in the db attachment table correctly, although the tag was not saved in the template record (I assume that this was because the 403 error interrupted the process).

    Checking the Image entry point class, I saw that it correctly fetches the list of allowed file types from the image metadata file, and there "image/svg+xml" is allowed, so I inserted the svg image into the template using the Image entry point instead.

    Is it by design that svg is allowed in the Image entry point but not allowed in the Attachment entry Point or a bug ?.

    If this is done purposely, then I think that the forbidden type of file (in this case svg) should not be uploaded when the Attachment entry point is invoked.

    In regards to TCPDF, the svg image displays correctly in the template (through the browser) after I inserted it as an image entry point but is not rendered when printed as a PDF

    Would this be also a design limitation of TCPDF or a possible bug ?

    Thanks
    Last edited by telecastg; 11-02-2021, 10:35 PM.

  • #2
    Hello telecastg
    i know this too.. rendered in browser but not in pdf.. i don't know why.
    if not forget, i have to include svg as base64encode and too same :s
    so i think, it's tcpdf issue
    Best Regards

    Comment


    • #3
      Thanks item I believe too that failure to render svg is not an Espo bug but a tcpdf issue.

      In further research, reading through the actual tcpdf.php plugin class, I saw this comment by the developers regarding the ImageSVG method (supposedly used to render svg images in PDF):

      NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
      So basically they are saying that svg is NOT supported, nothing to do with Espo.

      In regards to the other issue: The inconsistency between the file types allowed at the image entry point class and the attachment entry point class, if it is done by design and not a bug, then I would suggest that in addition of throwing a 403 error, the system should not allow svg files to upload when done through the attachment entry point to avoid having "orphan" files and records.

      Hopefully yuri or someone from the development team can shed some light on this.

      Best Regards
      Last edited by telecastg; 11-03-2021, 04:59 AM.

      Comment


      • #4
        I will fix Attachment entryPoint.

        Regarding TCPDF, I didn't expect SVG to work in TCPDF. If somebody find a workaround for it I will appreciate.

        Comment


        • #5
          Fix: https://github.com/espocrm/espocrm/c...5e2471497d2d19

          Comment


        • #6
          Hello telecastg

          I have not skill but i think it's possible... maybe someone can continue, it's out of my skill
          i have modified :
          tcpdf : line 19375

          PHP Code:
          case 'tcpdf': {
          if (
          defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) {
          // Special tag used to call TCPDF methods

          if (isset($tag['attribute']['method'])) {
          $tcpdf_method $tag['attribute']['method'];
          if (
          method_exists($this$tcpdf_method)) {
          if (isset(
          $tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
          if (
          $tag['attribute']['method'] == 'ImageSVG')
          {
          $params urldecode($tag['attribute']['params']);
          call_user_func(array($this$tcpdf_method) , $params );
          }else{
          $params $this->unserializeTCPDFtagParameters($tag['attribute']['params']);
          call_user_func_array(array($this$tcpdf_method), $params);
          }
          } else {

          $this->$tcpdf_method();
          }
          $this->newline true;
          }
          }
          }
          break; 
          i have modified :
          Tools/Pdf/Tcpdf/entityProcessor
          function composeBarcodeTag line 212 .. change if/then/else in switch(). (i don't know how create a function for SVG)
          PHP Code:
          case 'SVG' :
          $function 'ImageSVG';
          $params '<svg xmlns="http://w....';
          return 
          "<tcpdf method="ImageSVG" params="" .urlencode('@' .$params) . "" />";
          break; 

          So what's is important for contrib :
          we can call from html (Espo/Tools/Pdf/Tcpdf/EntityProcessors.php) .. custom function
          "<tcpdf method="ImageSVG" params="" .urlencode('@' .$params) . "" />";

          the issue was .. ImageSVG wait a string (if i understand..) and BarCode is array..
          so it's why i modified tcpdf.php file.
          call_user_func
          call_user_func_array

          What we need, a file svg like
          '@' .'<svg> .... </svg>'
          the '@' => string
          whithout the '@' => file svg

          So we need to replicate composeBarcodeTag for imageSVG i think.

          public function ImageSVG($file, $x='', $y='', $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) {

          and i have called in template like so :

          {{barcodeImage id type='SVG' width=60 height=30 fontsize=14 text=true padding=0}

          important : type='SVG' .. the rest actually is hard coded :s

          Best Regards

          PS : svg image : https://svgstudio.com/pages/free-sample


          Attached Files
          Last edited by item; 11-03-2021, 10:26 PM.

          Comment


          • telecastg
            telecastg commented
            Editing a comment
            Hello friend ,

            The problem is that the method ImageSVG does not work to render either an svg file or the raw svg text from a tag.

            I tried both. When an .svg file is provided as image source it just ignores it. If the <svg> tag is provided it just prints is contents (the actual svg code).

            I checked on github and tcpdf is now considered obsolete by its developers, it has been replaced by a project in progress https://github.com/tecnickcom/tc-lib-pdf#readme

            Being that the old tcpdf class is quite complicated, and considered obsolete by its own developers, I don't think that it would be worth the learning curve and work necessary to overcome its many limitations.

            I know that many participants, like me too, would love to be able to use a different pdf engine, but as yuri has pointed it out, there don't seem to be any better alternatives for Espo at least for the moment. Perhaps when tc-lib-pdf is completed we will be able to have a decent PDF engine.

            Best regards
            Last edited by telecastg; 11-04-2021, 01:08 AM.

          • esforim
            esforim commented
            Editing a comment
            I think tcpdf is getting update to a major development at the moment: https://github.com/tecnickcom/tc-lib-pdf

            Only one mention of SVG support is as follow: https://github.com/tecnickcom/tc-lib...ment-258521426
            "The new SVG support will be added once the basic functionalities will be reimplemented."

            Date in 2016 though, it been 5 years now and it still in development so who know when it will be ready for release or v1.

            Feature request promised as follow:

            "supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/script/formats.php)"

        • #7
          heuuuu..
          as you know.. my english is perfect
          we need just between tag <svg> ... </svg>

          file_get_content
          ..remove unessary char..

          and now you have my skill on drawing

          Comment


          • #8
            all modified file is here.
            and on pdf : {{barcodeImage type='SVG' }} because all is hard coded in files attachment.

            if someone can make same behaviour of the function composeBarcodeTag .. but with composeSvgTag .. the rest is simply.

            Attached Files

            Comment

            Working...
            X