Php TCPDF适合页面(缩小比例)

Php TCPDF适合页面(缩小比例),php,tcpdf,Php,Tcpdf,我在我的项目中使用TCPDF(第一次)。 在过去的两天里,我已经完成了PDF的创建和保存 我现在有一个问题。数据是动态生成的,高度会略有不同。有没有一种方法可以像MS office中用于缩放的选项那样“适合页面” 下面是PHP代码 function generateProformaContent($user,$quote,$datas) { $datas=json_decode($datas); foreach($datas as $data) { for

我在我的项目中使用TCPDF(第一次)。 在过去的两天里,我已经完成了PDF的创建和保存

我现在有一个问题。数据是动态生成的,高度会略有不同。有没有一种方法可以像MS office中用于缩放的选项那样“适合页面”

下面是PHP代码

function generateProformaContent($user,$quote,$datas)
{
    $datas=json_decode($datas);
    foreach($datas as $data)
    {
        foreach ($quote->products as $product)
        {
            if($data->productName==$product->name)
            {
                $product->totalPacks=$data->packs;
            }
        }
    }
    unset ($datas);
    $content=
<<<EDO
    <table border="1" cellpadding="10" cellspacing="0">
        <thead>
            <tr >
                <td align="center"><b>Proforma Invoice</b></td>
            </tr>
        </thead>
    </table>
    <table border="1" cellpadding="10" cellspacing="0">
        <thead>
            <tr style="background-color:#004269;color:#FFFFFF;">
                <td align="center">
                    <b>Consignor Address</b>
                </td>
                <td align="center">
                    <b>Consignor Details</b>
                </td>
                <td align="center">
                    <b>Proforma Details</b>
                </td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td vertical-align="top">
                    <div>Company Name</div>
                    <div>Address</div>
                    <div>Phone Number</div>
                    <div>Website</div>
                </td>
                <td vertical-align="top">
                    <div>GST :</div>
                    <div>CST :</div>
                    <div>ECC :</div>
                </td>
                <td vertical-align="top">
                    <div>Date</div>
                    <div>PI No.: #NO.</div>
                </td>
            </tr>
        </tbody>
    </table>
    <table border="1" cellpadding="10" cellspacing="0">
        <thead>
            <tr style="background-color:#004269;color:#FFFFFF;">
                <td align="center">
                    <b>Consignee Address</b>
                </td>
                <td align="center">
                    <b>Consignee Details</b>
                </td>
                <td align="center">
                    <b>Shipment Details</b>
                </td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td vertical-align="top">
                    <div>Company Name</div>
                    <div>Address</div>
                </td>
                <td vertical-align="top">
                    <div>GST :</div>
                    <div>CST :</div>
                    <div>ECC :</div>
                </td>
                <td vertical-align="top">
                    <div>No Of Packs :</div>
                    <div>Gross Weight:</div>
                    <div>Freight Type:</div>
                    <div>Est. Date Of Shipping:</div>
                </td>
            </tr>
        </tbody>
    </table>
    <table border="1" cellpadding="10" cellspacing="0">
        <thead>
            <tr style="background-color:#004269;color:#FFFFFF;">
                <td align="center"><b>Product Summary</b></td>
            </tr>
        </thead>
    </table>
    <table border="1" cellpadding="5" cellspacing="0">
        <thead>
            <tr>
            <td width="40">No.</td>
            <td width="100">Name</td>
            <td width="50" align="right">Rate</td>
            <td width="50" align="center">Unit</td>
            <td width="68" align="right">Quantity</td>
            <td width="100" align="right">Subtotal</td>
            <td width="100" align="center">Tax Rate</td>
            <td width="100" align="right">Tax Amt.</td>
            <td width="100" align="right">Total</td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td width="40">No.</td>
                <td width="100">Name</td>
                <td width="50" align="right">Rate</td>
                <td width="50" align="center">Unit</td>
                <td width="68" align="right">Quantity</td>
                <td width="100" align="right">Subtotal</td>
                <td width="100" align="center">Tax Rate</td>
                <td width="100" align="right">Tax Amt.</td>
                <td width="100" align="right">Total</td>
            </tr>
        </tbody>
    </table>
    <table border="1" cellpadding="10" cellspacing="0">
        <tbody>
            <tr>
                <td width="408" vertical-align="top">
                    <div>Payment Terms : </div>
                    <div>Freight : </div>
                    <div>Our Bank Details</div><br>
                    <table border="1" cellpadding="4" cellspacing="0">
                        <tr>
                            <td width="100">Bank</td>
                            <td width="200"></td>
                        </tr>
                        <tr>
                            <td width="100">Account Holder</td>
                            <td width="200"></td>
                        </tr>
                        <tr>
                            <td width="100">Account No.</td>
                            <td width="200"></td>
                        </tr>
                        <tr>
                            <td width="100">IFSC Code</td>
                            <td width="200"></td>
                        </tr>
                        <tr>
                            <td width="100">Branch Code</td>
                            <td width="200"></td>
                        </tr>
                    </table>
                </td>
                <td width="300" vertical-align="top">
                    <br>
                    <table border="1" cellpadding="10" cellspacing="0">
                        <tr>
                            <td width="125">Total Taxable Amt.</td>
                            <td width="150"></td>
                        </tr>
                        <tr>
                            <td width="125">Total Tax</td>
                            <td width="150"></td>
                        </tr>
                        <tr>
                            <td width="125">Grand Total</td>
                            <td width="150"></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
    <table border="1" cellpadding="10" cellspacing="0">
        <tbody>
            <tr>
                <td width="408">Disclaimer: This is a digitally generated document. Signature is not required.</td>
                <td width="300">Date:</td>
            </tr>
        </tbody>
    </table>
EDO;
    return $content;

}
function createProformaPFD()
{
    require_once('tcpdf/tcpdf.php');
    //print_r($_POST);
    //getting UserName
    $pdo=database::connect();
    $sql=$pdo->prepare("SELECT DatabaseName,InternalID FROM users WHERE ID=:id");
    $sql->bindParam("id",$_POST["user"]);
    $sql->execute();
    $sql=$sql->fetch(PDO::FETCH_OBJ);
    $database=$sql->DatabaseName;
    $userID=$sql->InternalID;
    $pdo=database::disconnect();
    $pdo=database::connect_db($database);
    $quote=new Quote($_POST["quote"],$database);
    $sql=$pdo->prepare("SELECT * FROM users WHERE ID=:id");
    $sql->bindParam("id",$userID);
    $sql->execute();
    $user=$sql->fetchObject();
    $pdo=database::disconnect();
    $content=generateProformaContent($user,$quote,$_POST["products"],$database);
    //echo $content;
    // create new PDF document
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

    // set document information
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Our Code World');
    $pdf->SetTitle('Example Write Html');

    // remove default header/footer
    $pdf->setPrintHeader(false);
    $pdf->setPrintFooter(false);
    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

    // set margins
    $pdf->SetMargins(5, 10, 5);

    // set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

    // set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

    // set some language-dependent strings (optional)
    if (@file_exists('tcpdf/examples/lang/eng.php')) {
        require_once('tcpdf/examples/lang/eng.php');
        $pdf->setLanguageArray($l);
    }

    // set font
    $pdf->SetFont('times', '', 9);

    // add a page
    $pdf->AddPage();

    $pdf->writeHTML($content, true, false, true, false, '');


    // reset pointer to the last page
    $pdf->lastPage();
    //Check Folder For PI
    if (!file_exists("$database/proforma/"))
        mkdir("$database/proforma/", 0777);
    //Close and output PDF document
    $pdf->Output($_SERVER['DOCUMENT_ROOT']."EasyQuotes/$database/proforma/proforma.pdf", 'F');
}
问候,,
Bhavil Jain.

您的代码在哪里。。。代码。。。代码…@shashi:添加了代码。PS:我不认为需要代码,因为这是一个与库相关的问题。我得到了我想要的输出,除了一件事。只需检查示例并遵循它们的结构。因为文档文件中有各种类型的示例。你已经有了主意。请设置$pageDimension=array('500300')//宽度,高度你的代码在哪里。。。代码。。。代码…@shashi:添加了代码。PS:我不认为需要代码,因为这是一个与库相关的问题。我得到了我想要的输出,除了一件事。只需检查示例并遵循它们的结构。因为文档文件中有各种类型的示例。你已经有了主意。请设置$pageDimension=array('500300')//宽度、高度
$(document).on("click","#generateProforma",function(){
            var products=collectdata(noOfProducts);
            var data={user:$("#userID").val(),quote:$("#quoteID").val(),products:JSON.stringify(products)};
            console.log(data);
            ajax_PDF(data,"createProformaPFD");
    });