-2
I’m using the DOMPDF
to print a CV that picks up the data via $_GET
of the URL.
When I "print" the file on the screen, just the HTML
, I can get exactly what I need, but when I try to turn the DOMPDF
with CSS in another location, it does not generate, only generates a blank screen...
How can I do the DOMPDF
understand this style sheet?
I also tried to add inline CSS, but it doesn’t recognize things like float
for example...
Can anyone give me a hand with using external CSS with DOMPDF? It is mandatory that I use it, I can not use something else like html2pdf for example.
Just follow my code:
<?php
error_reporting(E_ALL);
$var1 = "";
$var2 = "";
$var3 = "";
$var5 = "";
$var6 = "";
$var7 = "";
require_once 'dompdf/autoload.inc.php';
include('../conexao.php');
$cpf = $_GET['cpf'];
$result_nome = mysqli_query($conexao, "SELECT * FROM profissionais WHERE cpf='$cpf'");
while($dados = mysqli_fetch_object($result_nome)) {
global $nome;
$nome = $dados->nome;
$var1 .= '
<html>
<head>
<link rel="stylesheet" href="../css/bootstrap.css" />
</head>
<body>
<div class="row">
<div class="card_CV col-md-10 col-xs-10 col-ls-10 offset-md-1">
<div class="row justify-content-sm-center">
<div class="col-lg-3 col-md-6 col-sm-11 text-center image-print"float:left; >
<div class="col text-center"><img class="imgCV mt-2" src="../imagem/perfil/'.$dados->foto.'">
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 text-center name-print">
<div><h3 class="mt-5">'.$dados->nome.'</h3>
<h5 class="text-info mt-2">'.$dados->profissao.'</h5></div>
</div>
<div class="col-lg-3 col-md-6 col-sm-6 text-center dados-print">
<div><label class="mt-4"><i class="fas fa-map-marker-alt mr-2"></i>'.$dados->cidade.' - '.$dados->estado.' </label></div>
<div><label class=""><i class="fas fa-phone-volume mr-2"></i>'.$dados->telefone.'</label></div>
<div><label class=""><i class="fas fa-envelope mr-2"></i>'.$dados->email.'</label></div>
</div>
</div>
<div class="row mt-5 ml-2">
<div class="col-11"><h4><i class="fas fa-bookmark mr-3"></i>Apresentação</h4></div>
<div class="col-12"><p>'.$dados->apresentacao.'</p></div>
</div>
</div>
';
}
$var1 .= '<div class="card_CV col-md-10 col-xs-10 col-ls-10 mt-3 offset-md-1">
<div class="row col mt-2 justify-content-end">
<h4 class="mr-auto ml-4">Formação Academica</h4>
</div>';
$var1;
$result_formacao = mysqli_query($conexao, "SELECT * FROM formacaoacademica WHERE cpf='$cpf'");
while($formacao = mysqli_fetch_object($result_formacao)) {
$var2 .= '
<div class=" col-12">
<div class="card mb-3">
<div class="card-body">
<div class="row">
<div class="col-6"><h5 class="card-title">'.$formacao->escola.'</h5>
</div>
<div class="row col-12">
<h6 class="card-subtitle font-weight-normal mb-2 text-muted">'.$formacao->curso.'</h6>
</div>
<div class="row col-12">
<h6 class="card-subtitle font-italic mb-2 text-info">'.$formacao->anoinicio.' - '.$formacao->anotermino.'</h6>
</div>
</div>
</div>
</div>
</div>
';
}
$var2;
$var3 .= '</div>
<div class="card_CV col-md-10 col-xs-10 col-ls-10 mt-3 offset-md-1">
<div class="row col mt-2 justify-content-end">
<h4 class="mr-auto ml-4">Licenças e certificados</h4>
</div>';
$result_certificados = mysqli_query($conexao, "SELECT * FROM certificadosprofi WHERE cpf='$cpf'");
while($certificado = mysqli_fetch_object($result_certificados)) {
$var5 .= '
<div class=" col-12">
<div class="card mb-3">
<div class="card-body">
<div class="row">
<div class="col-6"><h5 class="card-title">'.$certificado->curso.'</h5>
</div>
<div class="row col-12">
<h6 class="card-subtitle font-weight-normal mb-2 text-muted">'.$certificado->escola.'</h6>
</div>
<div class="row col-12">
<h6 class="card-subtitle font-italic mb-2 text-info">'.implode('/', array_reverse(explode('-', $certificado->data))).'</h6>
</div>
</div>
</div>
</div>
</div>
';
}
$var5;
$var6 .= '</div>
<div class="card_CV col-md-10 col-xs-10 col-ls-10 mt-3 offset-md-1" style="margin-bottom: 3%; padding-bottom: 2%">
<div class="row col mt-2 justify-content-end">
<h4 class="mr-auto ml-4">Experiência Profissional</h4>
</div>';
$result_experiencia = mysqli_query($conexao, "SELECT * FROM experienciaprofissional WHERE cpf='$cpf'");
while($experiencia = mysqli_fetch_object($result_experiencia)) {
$var7 .= '
<div class="card-body" style="background-color: #fff; border: 1px solid rgba(0, 0, 0, 0.125)">
<div class="row">
<div class="col-6">
<h5 class="card-title">'.$experiencia->empresa.'</h5>
</div>
</div>
<div class="row col-12">
<h6 class="card-subtitle font-weight-normal mb-2 text-muted">'.$experiencia->funcao.'</h6>
</div>
<div class="row col-12">
<h6 class="card-subtitle font-italic mb-2 text-info">'.implode('/', array_reverse(explode('-', $experiencia->admissao))).' - '.implode('/', array_reverse(explode('-', $experiencia->demissao))).'</h6>
</div>
<div class="row col-12">
<h6 class="card-subtitle font-weight-normal mb-3 mt-2 text-muted">'.$experiencia->localidade.'</h6>
</div>
<div class="row col-12">
<p class="mb-2">'.$experiencia->responsabilidade.'</p>
</div>
</div>
</body>
</html>
';
}
$var7;
$encoding = mb_internal_encoding();
//$encoding = mb_internal_encoding();
$content = $var1 . $var2 . $var3 . $var5 . $var6 . $var7;
use Dompdf\Dompdf;
$dompdf = new DOMPDF();
//$dompdf->set_base_path("public_html/css/");
// Carrega seu HTML
$dompdf->load_html($content);
//Renderizar o html
$dompdf->render();
//Exibir a página
$dompdf->stream(
$nome."cv.pdf",
array(
"Attachment" => false //Para realizar o download somente alterar para true
)
);
?>
This is a symptom of an error in the code. Have you debugged this in the log? Is there anything you’re not letting the library render PHP output.
– ShutUpMagda