2016-07-11 10 views
2

Ich habe eine html Seite wie JsFiddle und ich möchte dies in pdf konvertieren, ich kann nicht die Zeile zu Zeile PDF erstellen, weil die Seite dynamisch erstellt wird, verwende ich PHP zum Aufruf eines Feldes die Verbindung zu MySQL und füllen Sie eine Vorlage wie.wie man Seite zu pdf in PHP konvertiert

$_POST['IdQuestionario']=5; 
$_POST['IdUtente']=10001; 
$_POST['Visualizza']=true; 
$_POST['IdImpianto']=1; 
$_POST['Stampa']=true; 
$_POST['TipoImpianto']='grande'; 

ob_start(); 
ob_clean(); 
require_once 'intro.php'; 
$tbl=ob_get_clean(); 
$html.=$tbl; 

Ich versuche, mit tcpf, mpdf, jsPDF, aber ich kann eine diskrete Ausgabe erhalten, weil ich colgroup für Tabelle. jemand sagt mir eine Methode zum Rendern der Seite, wenn es möglich ist, keine Software auf dem Server zu installieren.

+0

Sie http://www.fpdf.org versucht haben? Sie können auch HTML einfügen –

+0

Ich versuche, aber die Datei ist nicht gut Format – Ossarotte

+0

können Sie den vollen Code, den Sie verwenden, buchen? –

Antwort

2

Dort ein paar, die ich kenne - einige haben Probleme mit Tabellen, ich würde DOMPDF - bekannte Probleme mit Tabellen vermeiden.

Es gibt einen, der von cvision empfohlen wird; Ich habe kein Codebeispiel, aber Sie können es kostenlos herunterladen und sogar online ausprobieren.

Es gibt auch ein php-pdf Produkt, das von muhimbi (etwas weniger bekannte !, aber ich denke, es ist kostenlos)

<?php 
// Include the generated proxy classes 
require_once "documentConverterServices.php"; 
// Check the uploaded file 
if ($_FILES["file"]["error"] > 0) 
{ 
    echo "Error uploading file: " . $_FILES["file"]["error"]; 
} 
else 
{ 
    // Get the uploaded file content 
    $sourceFile = file_get_contents($_FILES["file"]["tmp_name"]); 

    // Create OpenOptions 
    $openOptions = new OpenOptions(); 
    // set file name and extension 
    $openOptions->FileExtension = pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION); 
    $openOptions->OriginalFileName = $_FILES["file"]["name"]; 
    // Create conversionSettings 
    $conversionSettings = new ConversionSettings(); 
    // Set the output format 
    if(isset($_POST["outputFormat"])) 
    { 
     $conversionSettings->Format = $_POST["outputFormat"]; 
    } else { 
     $conversionSettings->Format = "PDF"; 
    } 
    // Set fidelity 
    $conversionSettings->Fidelity = "Full"; 
    // These values must be set to empty strings or actual passwords when converting to non PDF formats 
    $conversionSettings->OpenPassword=""; 
    $conversionSettings->OwnerPassword=""; 
    // Set some of the other conversion settings. Completely optional and just an example 
    $conversionSettings->StartPage = 0; 
    $conversionSettings->EndPage = 0; 
    $conversionSettings->Range = "VisibleDocuments"; 
    $conversionSettings->Quality = "OptimizeForPrint"; 
    $conversionSettings->PDFProfile = "PDF_1_5"; 
    $conversionSettings->GenerateBookmarks = "Automatic"; 
    $conversionSettings->PageOrientation="Default"; 
    // Create the Convert parameter that is send to the server 
    $convert = new Convert($sourceFile, $openOptions, $conversionSettings); 
    // Create the service client and point it to the correct Conversion Service 
    $url = "http://localhost:41734/Muhimbi.DocumentConverter.WebService/?wsdl"; 
    $serviceClient = new DocumentConverterService(array(), $url); 

    // If you are expecting long running operations then consider longer timeouts 
    ini_set('default_socket_timeout', 60); 

    try 
    { 
     // Execute the web service call 
     $result = $serviceClient->Convert($convert)->ConvertResult; 
     // Send the resulting file to the client. 
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
     header("Content-type: application/octet-stream"); 
     header("Content-Disposition: attachment; filename=\"convert." . $conversionSettings->Format . "\""); 
     echo $result; 
    } 
    catch (Exception $e) 
    { 
     print "Error converting document: ".$e->getMessage(); 
    }  
} 
?> 

Auch könnten Sie 'Snappy' (hat Abhängigkeiten)

+0

https://tcpdf.org/ - derzeit nicht kostenlos, aber bald kostenlos (neue Version in Entwicklung auf github. Http://docraptor.com/ - auch bezahlt, aber kostenlos Versuch. –

Verwandte Themen