2016-07-11 2 views
2

私はJsFiddleのようなhtmlページを持っていますが、pdfでこれを変換したいのですが、ページがdinamicallyに作成されているため、 mysqlに接続し、次のようなテンプレートファイルを入力します。PHPでページをPDFに変換する方法

$_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; 

私はtcpf、MPDF、jsPDFにしようとしているが、私はテーブルのためCOLGROUPを使用するので、私は個別の出力を得るカント。サーバーにソフトウェアをインストールすることが可能であれば誰でも私にページをレンダリングする方法を教えてくれます。

+0

のラッパーであるあなたはhttp://www.fpdf.orgを試してみたのですか?あなたも同様にhtmlを挿入することができます –

+0

私はしようとするが、ファイルがよくフォーマットされていない – Ossarotte

+0

あなたが使用する完全なコードを投稿することはできますか? –

答えて

2

いくつか私が知っている - いくつかのテーブルに問題がある、私はDOMPDF - テーブルとの既知の問題を避けるだろう。

cvisionからお勧めのものがあります。私はコードサンプルを持っていませんが、無料でダウンロードしてオンラインでサンプルすることもできます。 muhimbiから入手できるPHP-PDF製品(少しあまり知られていない!しかし、私はそれは自由だと思う)

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

はまたもあります

、あなたは'Snappy'(依存関係を持っている)

+0

https://tcpdf.org/ - 現在は無料ではありませんが、すぐに無料になります(githubで開発中の新しいバージョンhttp://docraptor.com/ - 有料でも無料ですトライアル。 –

関連する問題