Skip to content

Instantly share code, notes, and snippets.

@devasia2112
Last active September 8, 2019 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devasia2112/d2110f22ec0ae0740fbffe1e7798bb18 to your computer and use it in GitHub Desktop.
Save devasia2112/d2110f22ec0ae0740fbffe1e7798bb18 to your computer and use it in GitHub Desktop.
gerador de PDF em massa, usar com o script: `Layout/Layout-Servico-Comunicacao-Multimidia.php`
/***
* Imprimir URI usando o binario phantomjs.
* execute o comando `phantomjs` e o PDF vai ser gerado no seu disco,
* execute `pkill -9 phantomjs` para matar o processo que as vezes
* persiste e faz uso extensivo dos recursos do servidor.
* Obs.: phantomjs requer o uso de `libfontconfig`, instalacao para ubuntu
* `apt-get install libfontconfig`
*
* O script foi testado com servidor Debian (Jessie).
*
* IMPORTANTE:
* - `phantomjs` encontrou problema com Ubuntu 18, usar Debian.
* - Usar esse script no momento da geracao do template no arquivo
* `Layout/Layout-Servico-Comunicacao-Multimidia.php` com os
* mesmos dados da classe `nfsc`.
*
***/
/**
* Executar esse bloco no loop
*/
$url = $protocol . "://$_SERVER[HTTP_HOST]/nfsc/Layout/Layout-Servico-Comunicacao-Multimidia.php?cliente=".trim($codigo_cliente)."&data_referente=".$data_referente."&periodo_apuracao=".$data_nf['0']['@periodoApuracao'];
$url = escapeshellarg($url);
$pdf = trim($codigo_cliente) . "_" . $data_nf['0']['@dataEmissao'] . "_" . $data_nf['0']['@periodoApuracao'] . ".pdf";
$pdf_filename = "PDF/" . $pdf; // NF em PDF
# adicione 2>&1 no final do comando para retornar `STDERR returned` e `STDOUT`
$cmdPhantom = '/var/www/nfsc/bin/phantomjs /var/www/nfsc/assets/rasterize.js ' . $url . ' ' . $pdf_filename . ' A4 2>&1';
$cmdPkill = 'pkill -9 phantomjs 2>&1';
$outputpkill = shell_exec($cmdPkill);
$output = shell_exec($cmdPhantom);
$outputpkill = shell_exec($cmdPkill);
# var_dump($output);
# reinicializar variaveis
$url = '';
$pdf = '';
$pdf_filename = '';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment