Created
June 1, 2018 10:19
-
-
Save rajithsam/fd3a10e092685da99775a2ce28126f49 to your computer and use it in GitHub Desktop.
Enviar PDF Base64 do jsPDF por E-mail Laravel 5.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// é 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