Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: mpdf generowanie pdf z pliku php.
Forum PHP.pl > Forum > PHP
ralothhardica
Witam serdecznie smile.gif Mam problem odnośnie generowania pliku pdf. Używam biblioteki mpdf.

  1. <?php
  2. include('mpdf/mpdf.php');
  3. $stylesheet = file_get_contents('./test/style.css');
  4. $html = file_get_contents('./test/file.php');
  5. $mpdf=new mPDF('UTF-8','A4','','' , 3,3,2,0,0,0);
  6. $mpdf->SetDisplayMode('fullpage');
  7. $mpdf->allow_charset_conversion=true;
  8. $mpdf->charset_in='UTF-8';
  9.  
  10. $mpdf->WriteHTML($stylesheet,1);
  11. $mpdf->list_indent_first_level = 0;
  12. $mpdf->SetWatermarkImage('./test/a.jpeg', 0.15, 'F');
  13. $mpdf->showWatermarkImage = true;
  14.  
  15. $mpdf->WriteHTML($html,2);
  16.  
  17. $mpdf->Output("output.pdf","D");
  18. ?>


file.php
  1. <html>
  2. .
  3. .
  4. <?php
  5. $text = 'tekst tekst tekst';
  6. ?>
  7. .
  8. .
  9. <p> zmianna text: <?php echo $text ?> </p>
  10. </html>


Problem polega na tym że po wygenerowaniu pdf nie mam zmianna text: tekst tekst tekst, tylko


<?php
$text = 'tekst tekst tekst';
?>
zmianna text: <?php echo $text ?>
nospor
file_get_contents pobiera tresc pliku a nie go wykonuje.
ralothhardica
czyli powinienem zrobić include?
nospor
No jeśli chcesz wykonać kod php, to tak. Tylko by to include nie wyleciało na ekran a do zmiennej, to musisz użyć funkcji z rodziny ob_
ralothhardica
A dokładniej mógłbyś mnie nakierować jak to zrobić? Użyć ob_start i ob_end_flus. Tak?
nospor
Manual.....

http://www.php.net/manual/pl/function.ob-get-flush.php
Cytat
echoed the ouput but I wanted it in a variable, not outputted immediately. Here's how:

<?php
// start generating html
$html = '<html><head>'; // etc
// start output buffering
ob_start();
// call function which outputs immediately
print_menu();
// append this to $html
$html .= ob_get_flush();
// empty output buffer
ob_clean();
ralothhardica
Zrobiłem tak:
  1. <?php
  2.  
  3. include('mpdf/mpdf.php');
  4. $stylesheet = file_get_contents('./test/style.css');
  5. $html = include('./test/file.php');
  6. $html .= ob_get_flush();
  7. $mpdf=new mPDF('UTF-8','A4','','' , 3,3,2,0,0,0);
  8. $mpdf->SetDisplayMode('fullpage');
  9. $mpdf->allow_charset_conversion=true;
  10. $mpdf->charset_in='UTF-8';
  11. $mpdf->WriteHTML($stylesheet,1);
  12. $mpdf->list_indent_first_level = 0;
  13. $mpdf->SetWatermarkImage('./test/a.jpeg', 0.15, 'F');
  14. $mpdf->showWatermarkImage = true;
  15. $mpdf->WriteHTML($html,2);
  16. $mpdf->Output("output.pdf","D");
  17. ?>

i wszystko jest na ekranie zamiast PDF.
nospor
Dałem ci linka, podałem ci kod z tego linka, gdzie masz zrobione to czego potrzebujesz, a ty tak jakbyś wogóle tego posta nie widział i zrobiłeś "po swojemu". Po co więc przychodzisz na forum skoro nie korzystasz z tego co ci ludzie dają?
ralothhardica
Czyli powinienem najpierw dać ob_start(); później zaincludować i ob_get_flash?
nospor
W kodzie co ci dałem print_menu(); to twoje include. Nic dodać, nic ująć.
ralothhardica
to i tak zrobiłem i tak wszystko wypluwa na ekran.
  1. .
  2. .
  3. .
  4. include('./test/file.php');
  5. $html .= ob_get_flush();
  6. .
  7. .
  8. .
nospor
  1. include('twojplik');
  2. $html .= ob_get_contents();
  3.  
ralothhardica
ok Wielkie dzięki smile.gif Wszystko działa smile.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.