Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> mpdf generowanie pdf z pliku php.
ralothhardica
post 16.05.2012, 09:45:47
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 16.05.2012

Ostrzeżenie: (0%)
-----


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 ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 12)
nospor
post 16.05.2012, 09:55:10
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




file_get_contents pobiera tresc pliku a nie go wykonuje.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
ralothhardica
post 16.05.2012, 10:13:07
Post #3





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 16.05.2012

Ostrzeżenie: (0%)
-----


czyli powinienem zrobić include?
Go to the top of the page
+Quote Post
nospor
post 16.05.2012, 10:28:57
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




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_


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
ralothhardica
post 16.05.2012, 15:54:20
Post #5





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 16.05.2012

Ostrzeżenie: (0%)
-----


A dokładniej mógłbyś mnie nakierować jak to zrobić? Użyć ob_start i ob_end_flus. Tak?
Go to the top of the page
+Quote Post
nospor
post 16.05.2012, 16:40:39
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




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();


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
ralothhardica
post 17.05.2012, 08:52:50
Post #7





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 16.05.2012

Ostrzeżenie: (0%)
-----


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.
Go to the top of the page
+Quote Post
nospor
post 17.05.2012, 08:57:01
Post #8





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




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ą?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
ralothhardica
post 17.05.2012, 09:16:04
Post #9





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 16.05.2012

Ostrzeżenie: (0%)
-----


Czyli powinienem najpierw dać ob_start(); później zaincludować i ob_get_flash?
Go to the top of the page
+Quote Post
nospor
post 17.05.2012, 09:21:00
Post #10





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




W kodzie co ci dałem print_menu(); to twoje include. Nic dodać, nic ująć.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
ralothhardica
post 17.05.2012, 09:34:32
Post #11





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 16.05.2012

Ostrzeżenie: (0%)
-----


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. .
Go to the top of the page
+Quote Post
nospor
post 17.05.2012, 09:40:26
Post #12





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




  1. include('twojplik');
  2. $html .= ob_get_contents();
  3.  


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
ralothhardica
post 17.05.2012, 10:41:14
Post #13





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 16.05.2012

Ostrzeżenie: (0%)
-----


ok Wielkie dzięki smile.gif Wszystko działa smile.gif
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 02:31