HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.30
System: Linux iZj6c1151k3ad370bosnmsZ 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: root (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: /var/www/html/amberconcept/test_pdf.php.bak20211116
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//include wp libriries and set timezone to HK
require_once('wp-load.php'); 
require_once('PHPExcel.php');
require_once('TCPDF/data/tcpdf_include.php');
date_default_timezone_set("Asia/Hong_Kong"); 
global $wpdb;

$order_id = $_GET['order_id'];
$order = wc_get_order($order_id);
$isFotomax = $order->get_user_id()==7?true:false;

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);

$pdf->SetAuthor('WH-HKMIS');
$pdf->SetTitle('AMBER PO');
$pdf->SetSubject('AMBER PO');
$pdf->SetKeywords('AMBER PO');
/*
$page_title = "";
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $page_title, PDF_HEADER_STRING);
*/
// set header and footer fonts
//$pdf->setHeaderFont(Array('stsongstdlight', '', 8));
$pdf->setPrintHeader(false);
$pdf->setFooterFont(Array('stsongstdlight', '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// 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(dirname(__FILE__).'/lang/eng.php')) {
	require_once(dirname(__FILE__).'/lang/eng.php');
	$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
//$pdf->SetFont('helvetica', '', 10);
//$pdf->SetFont('stsongstdlight', '', 10);
$pdf->SetFont('DroidSansFallback', '', 8, '', true);

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


// draw header table
$htmlHeader = '<div id="headerSection">';

$htmlHeader .= '
<table cellspacing="2" cellpadding="2">
    <tr>
        <td>
			<table id="po_table" cellspacing="1" cellpadding="1">
				<tr>
					<td colspan="2"><h1>PURCHASE ORDER</h1></td>
				</tr>
				<tr>
					<td></td><td></td>
				</tr>
				<tr>					
					<td>DATE:</td><td>'.date('F d, Y', strtotime($order->get_date_created())).'</td>
				</tr>
				<tr>					
					<td>VENDOR NO.:</td><td>Wink Impression</td>
				</tr>
				<tr>					
					<td>ORDER ID:</td><td>PO# '.$order->get_order_number().'</td>					
				</tr>
			</table>
		</td>
        <td></td>
        <td>
			<table id="amber_table" cellspacing="1" cellpadding="1" style="text-align: right;">
				<tr>
					<td><img src="custom/image/Amber.png" width="150"></td>
				</tr>				
				<tr>					
					<td><small>Flat 6A, Kin Ho Industrial Building, Block 1<br>14-24 Au Pui Wan Street, Fotan, NT, HK</small></td>
				</tr>
				<tr>					
					<td><small>Tel: 852-2278 5768<br>Fax: 852-2691 0724<br>Email: cs.hk@amberconcept.com</small></td>
				</tr>				
			</table>
		</td>
    </tr>
</table>';
$htmlHeader .= '</div>';

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

$pdf->Line(10, 38, 200, 38, array('width' => 0.7));

// draw address table
$htmlAddress = '<div id="addressSection">';

$htmlAddress .= '
<table cellspacing="0" cellpadding="0" border="1">
    <tr>
        <td width="30%">
			<table id="vendor_table" cellspacing="1" cellpadding="1">
				<tr style="background-color:#000;color:#FFF">
					<td>Vendor</td>
				</tr>
				<tr>
					<td>Wink Impression</td>
				</tr>
				<tr>
					<td>中國廣東省東莞市樟木頭鎮莞樟東路311號</td>
				</tr>
				<tr>
					<td>Tel: (+86) 076987191122</td>
				</tr>	
				<tr>
					<td>Fax: (+86) 076987782619</td>
				</tr>	
				<tr>
					<td>Email: hongli_pang@w-impression.com</td>
				</tr>	
				<tr>
					<td>Attn: 紅麗</td>
				</tr>																					
			</table>
		</td>  
        <td width="30%">
			<table id="ship_table" cellspacing="1" cellpadding="1">
				<tr style="background-color:#000;color:#FFF">
					<td>Ship To</td>
				</tr>
				<tr>
					<td>Amber Concept Ltd.</td>
				</tr>
				<tr>
					<td>Flat 6A, Blk 1, Kin Ho Industrial Building</td>
				</tr>
				<tr>
					<td>14-24 Au Pui Wan St. Fotan, HK</td>
				</tr>				
				<tr>
					<td>Tel: (852) 2278 5700</td>
				</tr>	
				<tr>
					<td>Fax: (852) 2691 0724</td>
				</tr>	
				<tr>
					<td>Email: sam.lee@amberconcept.com</td>
				</tr>	
				<tr>
					<td>Attn: Sam Lee</td>
				</tr>																					
			</table>
		</td> 
        <td width="40%">
			<table id="other_table" cellspacing="1" cellpadding="1">
				<tr style="background-color:#000;color:#FFF">
					<td colspan="2">Other Information</td>
				</tr>
				<tr>
					<td>Ship Via: </td><td>'.$order->get_shipping_method().'</td>
				</tr>
				<tr>
					<td>Shipment Term: </td><td>FOB</td>
				</tr>
				<tr>
					<td>Payment Term: </td><td>Net 30 Days</td>
				</tr>	
				<tr>
					<td>Request Delivery Date: </td><td>'.($isFotomax?'Fotomax單, 7日內交':'10日內交').'</td>
				</tr>
				<tr>
					<td>Courier: </td><td>Fedex/SF Express/GE-DHL</td>
				</tr>	
				<tr>
					<td>Shippng Document Value: </td><td>US$50 /pc</td>
				</tr>																									
				<tr>
					<td>Weight & Ctn Size: </td><td>Pls see packing list</td>
				</tr>
			</table>
		</td> 				      
    </tr>	
</table>';

$htmlAddress .= '</div>';
$pdf->writeHTML($htmlAddress, true, false, false, false, '');

// draw product table
$htmlProduct = '<div id="productSection">';

$htmlProduct .= '
<table cellspacing="0" cellpadding="0" border="1">
    <tr>
        <td>
			<table id="product_table" cellspacing="1" cellpadding="1">
				<tr style="background-color:#000;color:#FFF">
					<td width="70%" align="left">Description</td>
					<td width="10%" align="center">Qty.</td>
					<td width="10%" align="center">Unit Price</td>
					<td width="10%" align="center">Total</td>
				</tr> ';
				foreach( $order->get_items() as $item_id => $item ) {					
					$product = wc_get_product( $item->get_product_id());
					$arr_categories = $product->get_category_ids();
					$str_category = "";
					foreach($arr_categories as $cat_id){
						$str_category .= get_the_category_by_ID($cat_id)."<br>";
					}
					
					$formatted_meta_data = $item->get_formatted_meta_data( '_', true );
					
					$htmlProduct .= '
						<tr>
							<td>
								<table cellpadding="2" cellspacing="2">
									<tr>
										<td>'.$item->get_name().'</td>
									</tr>';
								foreach($formatted_meta_data as $metaObj){
								$htmlProduct .= '<tr>
													<td>'.$metaObj->display_key.': '.strip_tags($metaObj->display_value).'</td>
												</tr>';
								}																		
					$htmlProduct .= '</table>
							</td>
							<td align="center">'.$item->get_quantity().'</td>
							<td align="center"></td>
							<td align="center"></td>
						</tr>';						
				}
				
$htmlProduct .= '																						
			</table>
		</td>        
    </tr>	
</table>';

$htmlProduct .= '</div>';
$pdf->writeHTML($htmlProduct, true, false, false, false, '');

// draw footer cell (left)
$displayFooter = $isFotomax?"Fotomax<br>(PO#".get_post_meta($order_id, 'Cusomter_po', true ).")":$order->get_formatted_shipping_address();

$pdf->SetFillColor(204,204,204);
$pdf->SetTextColor(0, 0, 0);
$pdf->writeHTMLCell(60, '', 10, 230, $displayFooter, 0, 1, 1, true, 'J', true);

// draw footer cell (right)
$htmlFooter = '
<table cellspacing="1" cellpadding="1" border="1">
	<tr>
		<td width="70%" align="right" style="background-color:#000;color:#FFF">Sub Total:</td>
		<td width="30%" align="center"></td>					
	</tr>
	<tr>
		<td width="70%" align="right" style="background-color:#000;color:#FFF">Discount:</td>
		<td width="30%" align="center"></td>					
	</tr>
	<tr>
		<td width="70%" align="right" style="background-color:#000;color:#FFF">Sales Tax Rate:</td>
		<td width="30%" align="center"></td>					
	</tr>
	<tr>
		<td width="70%" align="right" style="background-color:#000;color:#FFF">Sales Tax:</td>
		<td width="30%" align="center"></td>					
	</tr>
	<tr>
		<td width="70%" align="right" style="background-color:#000;color:#FFF">Other Cost:</td>
		<td width="30%" align="center"></td>					
	</tr>
	<tr>
		<td width="70%" align="right" style="background-color:#000;color:#FFF">Grand Total:</td>
		<td width="30%" align="center"></td>					
	</tr>
</table>';
// draw date cell (left)
$htmlDate = '<table id="dateSection" width="100%">
				<tr>
					<td><h1>'.date('F d, Y', strtotime($order->get_date_created())).'</h1></td>
			 	</tr>
				<tr>
					<td><hr></td>
			 	</tr>
				<tr>
					<td>Date</td>
			 	</tr>								
			 </table>';
// draw sign cell (right)			 
$htmlSign = '<table id="signSection" width="100%">
				<tr>
					<td><h1>Sam Lee</h1></td>
			 	</tr>
				<tr>
					<td><hr></td>
			 	</tr>
				<tr>
					<td>Authorized Signature</td>
			 	</tr>								
			 </table>';			 

//$pdf->writeHTML($htmlFooter, true, false, false, false, '');
$pdf->SetFillColor(255, 255, 255);
$pdf->writeHTMLCell(60, '', 140, 230, $htmlFooter, 0, 1, 1, true, 'J', true);
$pdf->writeHTMLCell(60, '', 10, 260, $htmlDate, 0, 1, 1, true, 'J', true);
$pdf->writeHTMLCell(60, '', 140, 260, $htmlSign, 0, 1, 1, true, 'J', true);

// reset pointer to the last page
$pdf->lastPage();

// ---------------------------------------------------------

$output_path = "/var/www/html/ossfs/amber/po/";
//Close and output PDF document
$pdf->Output($output_path.'TEST.pdf', 'I');
//echo $htmlProduct;
//============================================================+
// END OF FILE
//============================================================+
?>