2
I am developing a dynamic report with mPDF, but I am not able to put my data inside a variable to be able to output it.
My page is designed like this:
$html = '<div class="box-content no-padding table-responsive relMembros">'
.'<table class="table table-bordered table-striped table-hover table-heading table-datatable" id="tabMembros">'
.' <thead>'
.' <tr>'
.' <th>Nome</th>'
.' <th>Telefone</th>'
.' <th>Aniversario</th>'
.' <th>Email</th>'
.' <th>Úsuario mobile</th>'
.' <th>Status</th>'
.' </tr>'
.' </thead>'
.' <tbody>';
$conexao = new ConexaoDatabase();
$sql = "MINHA QUERY";
$sqlVars = array();
$sqlVars[':igj'] = $suc->getCOD_IDENT_IGREJ();
$registros = $conexao->fetchAll($sql, $sqlVars);
if ($registros) {
foreach ($registros as $registro) {
echo '<tr>'
. '<td>' . $registro->TXT_NOMEX_PESSO . '</td>'
. '<td>' . $registro->TXT_FONEX_PESSO . '</td>'
. '<td>' . $registro->DAT_NASCI_PESSO . '</td>'
. '<td>' . $registro->TXT_EMAIL_PESSO . '</td>'
. '<td>' . $registro->FLG_USUAR_MOBIL . '</td>'
. '<td>' . $registro->FLG_STATU_PESSO . '</td>'
. '</tr>';
}
} else {
//echo 'Não existe vinculo para está pessoa.';
}
$html = $html . '</tbody>'
.'</table>'
.'</div>';
include("../pdf/mpdf60/mpdf.php");
$mpdf=new mPDF();
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->list_number_suffix = ')';
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
?>
To open this page I am using AJAX to load the core of my index.
Bag of mPDF also ?
– Renan Rodrigues
I never used it. I use the FPDF without the HTML part (In the FPDF you draw directly in the page positions).
– Bacco
Because he is opening the PDF on the same page, or is not interpreting the command but putting all that code on the screen
– Renan Rodrigues
Ai ta missing hit the headers.
– Bacco
you know how it would be ?
– Renan Rodrigues
header("Content-type:application/pdf");
and if you want to force downloadheader("Content-Disposition:attachment;filename='downloaded.pdf'");
- usually the first one is enough. Remember that this is right at the beginning of the page, before any data is sent. You can’t even have space before the first<?php
not to interfere.– Bacco
it’s not worked
– Renan Rodrigues
see that you’re calling $mpdf->Writehtml($html); twice, I think it’s kind of weird that too.
– Bacco
You say that "is opening on the same page"... There is more on the page besides the PDF? Can not mix. Either you serve the page to open in the browser, or you make the PDF. It has to be PHP separated for two things (or have a logic to show only one thing or only the other).
– Bacco
Yes, because I do next, I have the index, inside the index I have a div chamaod content, when I click the button to generate the pdf it redirects me via ajax to the page where I put the content inside the index.
– Renan Rodrigues
So, you have to separate this logic. Either show on the screen, or generate the pdf. If you want you can even put a link in the part that shows on the screen, but this link has to call PHP again to generate PDF.
– Bacco
Let’s just see how to do this kkkk
– Renan Rodrigues
To simplify, you can make an if( $_GET['PDF'] == 1 ) shows on the screen, and shows the link contents.php? PDF=1 ELSE sends the headers, and makes the output. So ajax will call without PDF=1, then it will output HTML. But if one clicks on the link, you have ? PDF=1 that changes the logic and only generates the PDF. Thus, the generation is the same, but the IF selects whether to HTML or PDF pro client.
– Bacco
I will try to implement here
– Renan Rodrigues
Good fun kkk. But if you screw up badly, remember that you can ask a separate question with the specific problem (but do not forget to put the relevant parts of the code). If you are going to "train", you can make a PDF version, and a single screen, to test, then you put it together in one. Or you can use includes.
geraconteudo.php
makes the HTML, then theajax.php
makes include ofgeraconteudo.php
and plays on the screen, and thepdf.php
also makes include thegeraconteudo.php
, but makes a PDF. So you separate everything and reuse.– Bacco
Get here, I’m opening a popup with the pdf
– Renan Rodrigues
I will see a way to treat the popup so it always open on the screen and inside a box I will see what I do. Thank you very much helped me
– Renan Rodrigues