在 OpenTBS 演示中替换了图像,这是在代码中的何处完成的?
In OpenTBS demo an image is replaced, where in code is this done?
我无法理解如何管理图像替换。因此,我查看了演示项目 (demo_ms_word.php),但找不到完成定义和实际图像替换的 PHP 代码。
模板
[b.number;ope=changepic;from=pic_[val].png;tagpos=inside;adjust;unique]
PHP(只展示主要部分,不包含输出)
// Initialize the TBS instance
$TBS = new clsTinyButStrong; // new instance of TBS
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load the OpenTBS plugin
// ------------------------------
// Prepare some data for the demo
// ------------------------------
// Retrieve the user name to display
$yourname = (isset($_POST['yourname'])) ? $_POST['yourname'] : '';
$yourname = trim(''.$yourname);
if ($yourname=='') $yourname = "(no name)";
// A recordset for merging tables
$data = array();
$data[] = array('rank'=> 'A', 'firstname'=>'Sandra' , 'name'=>'Hill' , 'number'=>'1523d', 'score'=>200, 'email_1'=>'sh@tbs.com', 'email_2'=>'sandra@tbs.com', 'email_3'=>'s.hill@tbs.com');
$data[] = array('rank'=> 'A', 'firstname'=>'Roger' , 'name'=>'Smith' , 'number'=>'1234f', 'score'=>800, 'email_1'=>'rs@tbs.com', 'email_2'=>'robert@tbs.com', 'email_3'=>'r.smith@tbs.com' );
$data[] = array('rank'=> 'B', 'firstname'=>'William', 'name'=>'Mac Dowell', 'number'=>'5491y', 'score'=>130, 'email_1'=>'wmc@tbs.com', 'email_2'=>'william@tbs.com', 'email_3'=>'w.m.dowell@tbs.com' );
// Other single data items
$x_num = 3152.456;
$x_pc = 0.2567;
$x_dt = mktime(13,0,0,2,15,2010);
$x_bt = true;
$x_bf = false;
$x_delete = 1;
// -----------------
// Load the template
// -----------------
$template = 'demo_ms_word.docx';
$TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8); // Also merge some [onload] automatic fields (depends of the type of document).
// ----------------------
// Debug mode of the demo
// ----------------------
if (isset($_POST['debug']) && ($_POST['debug']=='current')) $TBS->Plugin(OPENTBS_DEBUG_XML_CURRENT, true); // Display the intented XML of the current sub-file, and exit.
if (isset($_POST['debug']) && ($_POST['debug']=='info')) $TBS->Plugin(OPENTBS_DEBUG_INFO, true); // Display information about the document, and exit.
if (isset($_POST['debug']) && ($_POST['debug']=='show')) $TBS->Plugin(OPENTBS_DEBUG_XML_SHOW); // Tells TBS to display information when the document is merged. No exit.
// --------------------------------------------
// Merging and other operations on the template
// --------------------------------------------
// Merge data in the body of the document
$TBS->MergeBlock('a,b', $data);
// Merge data in colmuns
$data = array(
array('date' => '2013-10-13', 'thin' => 156, 'heavy' => 128, 'total' => 284),
array('date' => '2013-10-14', 'thin' => 233, 'heavy' => 25, 'total' => 284),
array('date' => '2013-10-15', 'thin' => 110, 'heavy' => 412, 'total' => 130),
array('date' => '2013-10-16', 'thin' => 258, 'heavy' => 522, 'total' => 258),
);
$TBS->MergeBlock('c', $data);
// Change chart series
$ChartNameOrNum = 'a nice chart'; // Title of the shape that embeds the chart
$SeriesNameOrNum = 'Series 2';
$NewValues = array( array('Category A','Category B','Category C','Category D'), array(3, 1.1, 4.0, 3.3) );
$NewLegend = "Updated series 2";
$TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);
// Delete comments
$TBS->PlugIn(OPENTBS_DELETE_COMMENTS);
有人可以指出定义并合并图像被替换的地方吗?
在模板中,该字段名为 [b.number;...]
,因此它与名为 'b' 的块(或字段)以及子项 number
.
我们看到它在 PHP 片段中对应于 $TBS->MergeBlock('a,b', $data);
。此代码将块 'a' 和 'b' 与记录集 $data.
合并
因此 [b.number;...]
与记录集 $data 的列 number
合并。你可以看到此列具有诸如“1523d”、“1234f”、...
等值
参数ope=changepic
使字段的值成为要替换图片的路径。但是最终的路径是用参数 from=pic_[val].png
安排的,这使得字段 '1523d' 的值对应于路径 'pic_1523d.png'。
画面就是这样改的
如果字段的值直接是要替换的图像的路径,则 ope=changepic
不需要参数 'from'。
我无法理解如何管理图像替换。因此,我查看了演示项目 (demo_ms_word.php),但找不到完成定义和实际图像替换的 PHP 代码。
模板
[b.number;ope=changepic;from=pic_[val].png;tagpos=inside;adjust;unique]
PHP(只展示主要部分,不包含输出)
// Initialize the TBS instance
$TBS = new clsTinyButStrong; // new instance of TBS
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load the OpenTBS plugin
// ------------------------------
// Prepare some data for the demo
// ------------------------------
// Retrieve the user name to display
$yourname = (isset($_POST['yourname'])) ? $_POST['yourname'] : '';
$yourname = trim(''.$yourname);
if ($yourname=='') $yourname = "(no name)";
// A recordset for merging tables
$data = array();
$data[] = array('rank'=> 'A', 'firstname'=>'Sandra' , 'name'=>'Hill' , 'number'=>'1523d', 'score'=>200, 'email_1'=>'sh@tbs.com', 'email_2'=>'sandra@tbs.com', 'email_3'=>'s.hill@tbs.com');
$data[] = array('rank'=> 'A', 'firstname'=>'Roger' , 'name'=>'Smith' , 'number'=>'1234f', 'score'=>800, 'email_1'=>'rs@tbs.com', 'email_2'=>'robert@tbs.com', 'email_3'=>'r.smith@tbs.com' );
$data[] = array('rank'=> 'B', 'firstname'=>'William', 'name'=>'Mac Dowell', 'number'=>'5491y', 'score'=>130, 'email_1'=>'wmc@tbs.com', 'email_2'=>'william@tbs.com', 'email_3'=>'w.m.dowell@tbs.com' );
// Other single data items
$x_num = 3152.456;
$x_pc = 0.2567;
$x_dt = mktime(13,0,0,2,15,2010);
$x_bt = true;
$x_bf = false;
$x_delete = 1;
// -----------------
// Load the template
// -----------------
$template = 'demo_ms_word.docx';
$TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8); // Also merge some [onload] automatic fields (depends of the type of document).
// ----------------------
// Debug mode of the demo
// ----------------------
if (isset($_POST['debug']) && ($_POST['debug']=='current')) $TBS->Plugin(OPENTBS_DEBUG_XML_CURRENT, true); // Display the intented XML of the current sub-file, and exit.
if (isset($_POST['debug']) && ($_POST['debug']=='info')) $TBS->Plugin(OPENTBS_DEBUG_INFO, true); // Display information about the document, and exit.
if (isset($_POST['debug']) && ($_POST['debug']=='show')) $TBS->Plugin(OPENTBS_DEBUG_XML_SHOW); // Tells TBS to display information when the document is merged. No exit.
// --------------------------------------------
// Merging and other operations on the template
// --------------------------------------------
// Merge data in the body of the document
$TBS->MergeBlock('a,b', $data);
// Merge data in colmuns
$data = array(
array('date' => '2013-10-13', 'thin' => 156, 'heavy' => 128, 'total' => 284),
array('date' => '2013-10-14', 'thin' => 233, 'heavy' => 25, 'total' => 284),
array('date' => '2013-10-15', 'thin' => 110, 'heavy' => 412, 'total' => 130),
array('date' => '2013-10-16', 'thin' => 258, 'heavy' => 522, 'total' => 258),
);
$TBS->MergeBlock('c', $data);
// Change chart series
$ChartNameOrNum = 'a nice chart'; // Title of the shape that embeds the chart
$SeriesNameOrNum = 'Series 2';
$NewValues = array( array('Category A','Category B','Category C','Category D'), array(3, 1.1, 4.0, 3.3) );
$NewLegend = "Updated series 2";
$TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);
// Delete comments
$TBS->PlugIn(OPENTBS_DELETE_COMMENTS);
有人可以指出定义并合并图像被替换的地方吗?
在模板中,该字段名为 [b.number;...]
,因此它与名为 'b' 的块(或字段)以及子项 number
.
我们看到它在 PHP 片段中对应于 $TBS->MergeBlock('a,b', $data);
。此代码将块 'a' 和 'b' 与记录集 $data.
因此 [b.number;...]
与记录集 $data 的列 number
合并。你可以看到此列具有诸如“1523d”、“1234f”、...
参数ope=changepic
使字段的值成为要替换图片的路径。但是最终的路径是用参数 from=pic_[val].png
安排的,这使得字段 '1523d' 的值对应于路径 'pic_1523d.png'。
画面就是这样改的
如果字段的值直接是要替换的图像的路径,则 ope=changepic
不需要参数 'from'。