protected function buildCommand($binary, $input, $output, array $options = [])
    {
        $command = $binary;
        $escapedBinary = escapeshellarg($binary);
        if (is_executable($escapedBinary)) {
            $command = $escapedBinary;
        }

        foreach ($options as $key => $option) {
            if (null !== $option && false !== $option) {
                if (true === $option) {
                    // Dont't put '--' if option is 'toc'.
                    if ($key == 'toc') {
                        $command .= ' ' . $key;
                    } else {
                        $command .= ' --' . $key;
                    }
                } elseif (is_array($option)) {
                    if ($this->isAssociativeArray($option)) {
                        foreach ($option as $k => $v) {
                            $command .= ' --' . $key . ' ' . escapeshellarg($k) . ' ' . escapeshellarg($v);
                        }
                    } else {
                        foreach ($option as $v) {
                            $command .= ' --' . $key . ' ' . escapeshellarg($v);
                        }
                    }
                } else {
                    // Dont't add '--' if option is "cover"  or "toc".
                    if (in_array($key, ['toc', 'cover'])) {
                        $command .= ' ' . $key . ' ' . escapeshellarg($option);
                    } elseif (in_array($key, ['image-dpi', 'image-quality'])) {
                        $command .= ' --' . $key . ' ' . (int) $option;
                    } else {
                        $command .= ' --' . $key . ' ' . escapeshellarg($option);
                    }
                }
            }
        }

        if (is_array($input)) {
            foreach ($input as $i) {
                $command .= ' ' . escapeshellarg($i) . ' ';
            }
            $command .= escapeshellarg($output);
        } else {
            $command .= ' ' . escapeshellarg($input) . ' ' . escapeshellarg($output);
        }

        return $command;
    }