Skip to content

Instantly share code, notes, and snippets.

@rajithsam
Created June 1, 2018 10:19
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 rajithsam/fd3a10e092685da99775a2ce28126f49 to your computer and use it in GitHub Desktop.
Save rajithsam/fd3a10e092685da99775a2ce28126f49 to your computer and use it in GitHub Desktop.
Enviar PDF Base64 do jsPDF por E-mail Laravel 5.4
<?php
public function enviarPorEmail() {
// gerando um nome para o arquivo
$caminhoDoArquivo = storage_path('projeto-'.uniqid().'.pdf');
// remover data type da string
$base64 = str_replace('data:application/pdf;base64,', '', STRING_PDF_BASE64);
// salvar a string em uma pasta temporária para servir de anexo
file_put_contents($caminhoDoArquivo, base64_decode($base64));
// enviar o e-mail
return $this->subject('Assunto')
->attach($caminhoDoArquivo, [
'as'=> 'Nome do Arquvio',
'mime' => 'application/pdf'
])
->view('mail.view');
}
?>
// é necessário jsPDF https://parall.ax/products/jspdf
var doc = new jsPDF("l", "mm", "a4");
doc.text(17, 20, "Meu PDF");
// gerar a string
var base64String = doc.output('datauristring');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment