wpdesk / wpdesk-mpdf
此软件包已被废弃,不再维护。未建议替代软件包。
为 WP Desk 插件添加前缀的 MPDF 库。
此软件包尚未发布版本,信息有限。
README
为灵活发票、灵活优惠券、打印订单和标签添加前缀的 mPDF 库。
当前版本:8.0.6
用法
<?php
namespace MyPluginPrefix;
use WPDesk\Mpdf\Mpdf;
use WPDesk\PDF\ConfigSample;
use WPDesk\PDF\FontsDataSample;
class PDF {
public function render() {
$config = new ConfigSample();
// Define a temporary path for mPDF.
// Do not set a directory where other files exist!
// Otherwise they will be deleted!
$config->set_temp_dir( dirname( __FILE__ ) . '/temp/' );
// You can change the dir font by adding another one.
// If you are changing the directory, move the default fonts into your project.
$config->set_font_dir( [ dirname( __FILE__ ) . '/fonts/' ] );
$fonts_data = new FontsDataSample();
// Adds full font (bold, italic, regular)
// The first argument is a slug that can be set to CSS, the second argument is the name of the .ttf file.
$fonts_data->set_font( 'opensans', 'OpenSans' );
// Adds a font without a bold file.
$fonts_data->set_font_without_bold( 'rubik', 'Rubik' );
// Adds a font without a italic file.
$fonts_data->set_font_without_italic( 'rubik', 'Rubik' );
// Adds a font without a bold and italic file.
$fonts_data->set_font_without_bold_italic( 'rubik', 'Rubik' );
// Set fonts data for mPDF.
$config->set_font_data( $fonts_data->get() );
$mpdf = Mpdf( [ $config->get() ] );
$mpdf->WriteHTML( '<h1>My PDF</h1>' );
return $mpdf->Output( '', \WPDesk\Mpdf\Output\Destination::STRING_RETURN
}
}