/**
  * Realiza merge entre mais de um Documento Imagem que compõe as Imagens do
  * Documento. Esta versão é anterior à implementação do DocumentoImagemAggregator
  * e por este motivo está depreciada. Sua utilização não é recomendada.
  * 
  * @todo Remover daqui. Não é função de Fábrica.
  * @deprecated since version 4.2.14
  * @param string $parDigital
  * @param array $parDocumentoImagens
  * @return \Documento\DocumentoImagemAggregator
  */
 private static function _appendImages($parDigital, $parDocumentoImagens = array())
 {
     $cfg = \Config::factory();
     //        $pdfMergedAbsoluteDest = $cfg->getParam('config.basepath') . '/cache/TEMP_PDF_DOCUMENTO_' . preg_replace( '/[., ]/', '', $parDigital . '_' . microtime() );
     $pdfMergedAbsoluteDest = $cfg->getParam('config.basepath') . '/cache/TESTE';
     if (!is_dir($pdfMergedAbsoluteDest)) {
         @mkdir($pdfMergedAbsoluteDest, 0777, true);
     }
     $arrPDFs = array();
     $i = 0;
     foreach ($parDocumentoImagens as $parDocumentoImagem) {
         $pdfPartialDocAbsoluteFilename = sprintf("{$pdfMergedAbsoluteDest}/%04d.pdf", ++$i);
         $arrPDFs[] = $pdfPartialDocAbsoluteFilename;
         //Reune nomes dos arquivos PDFs
         //Salva em arquivos PDFs temporários
         $retorno = file_put_contents($pdfPartialDocAbsoluteFilename, $parDocumentoImagem->getPDF()->getData());
     }
     $finalFileName = "{$pdfMergedAbsoluteDest}/final.pdf";
     $cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile={$finalFileName} ";
     foreach ($arrPDFs as $pdfFilename) {
         $cmd .= $pdfFilename . " ";
     }
     shell_exec($cmd);
     foreach ($arrPDFs as $pdfFilename) {
         @unlink($pdfFilename);
     }
     //Recupera FLG_PUBLICO do ultimo documento enviado
     $rowLastImage = $parDocumentoImagens[count($parDocumentoImagens) - 1]->getRowSet();
     /**
      * @TODO: REFAZER
      */
     $documentoImagemPDF = new \Documento\Imagem\DocumentoImagemPDF();
     $documentoImagemPDF->newImage($parDigital, $finalFileName, $rowLastImage[0]['FLG_PUBLICO']);
     //        @rmdir($pdfMergedAbsoluteDest);
     //        unlink($pdfMersgedAbsoluteFilename);//apaga o diretório
     return self::factory($parDigital);
 }