修改生成长表格返回

This commit is contained in:
chengxl
2026-01-20 17:36:20 +08:00
parent 40f25544fa
commit f954c4b772

View File

@@ -3590,12 +3590,23 @@ class Production extends Base
$success = $this->generatePdfFromTex($tex_file, $pdfFilePath);
if($success){
// if($success){
// $this->production_article_obj->where("p_article_id",$production_info['p_article_id'])->update(['file_sub_table'=>'tex_'.$article_id.DS."table.pdf"]);
// }
// $frag['success'] = $success;
// $frag['file'] = $pdfFilePath;
// return $frag;
$iStatus = empty($success['status']) ? 0 : $success['status'];
if($iStatus != 1){
return json_encode($success);
}
if($iStatus == 1){
$this->production_article_obj->where("p_article_id",$production_info['p_article_id'])->update(['file_sub_table'=>'tex_'.$article_id.DS."table.pdf"]);
}
$frag['success'] = $success;
$frag['file'] = $pdfFilePath;
return $frag;
// return $frag;
return json_encode(['status' => 1,'msg' => 'Table generated successfully']);
// if ($success) {
// return jsonSuccess([
@@ -3622,12 +3633,13 @@ class Production extends Base
* @param string $pdfFilePath 输出PDF文件路径
* @return bool 是否生成成功
*/
public function generatePdfFromTex($texFilePath, $pdfFilePath)
public function generatePdfFromTex($texFilePath, $pdfFilePath)
{
try {
// 检查.tex文件是否存在
if (!file_exists($texFilePath)) {
throw new Exception("LaTeX文件不存在: " . $texFilePath);
// throw new Exception("LaTeX文件不存在: " . $texFilePath);
return ['status' => 2,'msg' => "LaTeX文件不存在: " . $texFilePath];
}
// 确保输出目录存在
@@ -3636,9 +3648,9 @@ class Production extends Base
mkdir($pdfDir, 0755, true);
}
// 方法1: 使用pdflatex命令推荐lualatex -output-directory=/path/to/output /path/to/input.tex
// $command = "pdflatex -include-directory=" . dirname($texFilePath) .
// " -output-directory=" . $pdfDir . " " . escapeshellarg($texFilePath);
// 方法1: 使用pdflatex命令推荐
// $command = "{$sLatexDir}pdflatex -include-directory=" . dirname($texFilePath) .
// " -output-directory=" . $pdfDir . " " . escapeshellarg($texFilePath);
$command = "lualatex -output-directory=" . $pdfDir . " " . escapeshellarg($texFilePath);
$output = [];
@@ -3647,21 +3659,25 @@ class Production extends Base
// 检查命令执行结果
if ($returnVar !== 0) {
error_log("LaTeX to PDF conversion failed: " . implode("\n", $output));
return false;
// error_log("LaTeX to PDF conversion failed: " . implode("\n", $output));
// return false;
return ['status' => 3,'msg' => "LaTeX to PDF conversion failed: " . implode("\n", $output)];
}
// 检查PDF文件是否生成成功
if (!file_exists($pdfFilePath)) {
error_log("PDF文件未生成: " . $pdfFilePath);
return false;
// error_log("PDF文件未生成: " . $pdfFilePath);
// return false;
return ['status' => 3,'msg' => "PDF文件未生成: " . $pdfFilePath];
}
return true;
// return true;
return ['status' => 1,'msg' => "PDF文件生成成功: " . $pdfFilePath];
} catch (Exception $e) {
error_log("生成PDF失败: " . $e->getMessage());
return false;
// error_log("生成PDF失败: " . $e->getMessage());
// return false;
return ['status' => 3,'msg' => "PDF文件未生成: " . $pdfFilePath];
}
}