-1

I am using DotKernel 1.8.0 on a project and when generating a long PDF file, with some data in it (using addText() pretty often). I get into an iconv() encoding error "Detected an illegal character in input string" which is a pretty straight forward error explanation.

When I check on the line of source code that produces the error (as mentions the backtrace) I am able to see which addText() call produces the error BUT I have now tried with simple "abcdef" text, so no special characters, and the error still happened. My website uses a UTF-8 charset.

I guess the error is linked to DotKernel changing from ISO to UTF-8 but I can't seem to find a solution to my problem. Any ideas, guesses that might help?

  • Would I have to change to using Zend_Pdf? - would it help at all?
  • Dot_Pdf searches on google do not deliver a lot of results, I hope anyone here can help!
Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
gs.evias
  • 1
  • 1

3 Answers3

1

You should build your class for processing PDF files, based on Zend_Pdf .

As there isn't such class as Dot_Pdf

The whole idea of DotKernel is to allow you to use directly Zend Framework classes. Which are considered production ready. Do no reinvent the weel.

Let me know if that fixes the issue. If not, please post some example code.

Dotkernel
  • 11
  • 1
1

You can also create a class which allows you to set the charset for all the document

class Dot_Pdf extends Zend_Pdf
{
    /**
     * The document charset
     * @var string $_charset
     */
    private $_charset;
    /**
     * Constructor for Zend_Pdf with Charset UTF-8
    */
    public function __construct()
    {
        parent::__construct();
        $this->setCharset();
    }

    /**
     * Set text charset
     * @access public
     * @param string $charset
     * @return bool $success
     */
     public function setCharset($charset = 'UTF-8')
     {
        // full charset list here http://a4esl.org/c/charset.html
        $charsetList = ['UTF-8', 'windows-1258', 'macintosh', 'windows-1252' ];

        if(in_array($charset, $charsetList))
        {
            // if valid
            $this->_charset = $charset;
            return true;
        }
        // if not valid
        return false;
     }

     /**
      * Draw Text - with collation
      * @access public
      * @param string $text
      * @param float $x
      * @param float $y
     */
     public function drawText($text, $x, $y)
     {
        parent::drawText($text, $x, $y, $this->_charset);
     }
}

The charset array is too big and not relevant right now. This way setting the wrong charset won't be a problem.

Gabi Dj
  • 645
  • 6
  • 15
0

The bugfix was solved by setting the encoding of the text draw to UTF-8. I guess Zend_Pdf defaults to another one.

My fix was a quick one where I needed to change the drawText() call to add the 'UTF-8' parameter such that I have :

$pdf->drawText("text", $x, $y, "UTF-8");

Hope this helps anyone in the futur ;)

gs.evias
  • 1
  • 1