2017-07-08 1 views
1

Ich möchte eine PDF-Datei aus einem HTML-Code, der die Stylesheet-Regeln enthält, mit PHP generieren.Generate PDF-Datei aus HTML-Code

Ich versuche es mit der MPDF-Bibliothek zu tun, aber wenn es generiert wird, sieht es nicht wie die HTML-Seite aus. Die meisten Elemente befinden sich nicht in der richtigen Position und werden wie einige CSS-Regeln nicht angewendet.

Weiß jemand, wie kann ich es gut aussehen lassen, bitte?

Antwort

0

Sie Wert von einer anderen Seite bekommen können auch post-Methode verwendet wird. Deine Entscheidung.

<?php $student_id = $_GET['student_id']; ?> 
<?php 
include("mpdf/mpdf.php"); 
$html .= " 
<html> 
<head> 
<style> 
body {font-family: sans-serif; 
    font-size: 10pt; 
    background-image: url(\"images/ok.jpg\"); 

    background-repeat: no-repeat; 
    padding-top:10pt; 
    margin-top: 100px; 
    padding-top: 50px; 
} 
td { vertical-align: top; 
    border-left: 0.6mm solid #000000; 
    border-right: 0.6mm solid #000000; 
    align: center; 
} 

p.student_id{ 
    padding-left : 140px; 
    padding-top : -27px; 
} 

</style> 
</head> 
<body> 
<!--mpdf                   

<p class=\"student_id\">$student_id</p> 


<sethtmlpageheader name='myheader' value='on' show-this-page='1' /> 
<sethtmlpagefooter name='myfooter' value='on' /> 
mpdf--> 


</body> 
</html> 
"; 

$mpdf=new mPDF(); 
$mpdf->WriteHTML($html); 
$mpdf->SetDisplayMode('fullpage'); 

$mpdf->Output(); 
?> 
0

Sie können Ihr eigenes Skript für docx Schöpfung in folgenden Weise verwenden.

<?php  
     header("Content-type: application/vnd.ms-word"); 
     header("Content-Disposition: attachment;Filename=document_name.docx"); 


     echo "<html>"; 
     echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">"; 
    ?> 
<body> 
    <h1> 
     <center>Title of the document</center> 
    </h1> 

    <p> 
     Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod 
     tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
     quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
     consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse 
     cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non 
     proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
    </p> 
    <p> 
     Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod 
     tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
     quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
     consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse 
     cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non 
     proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
    </p> 
</body>