2
0

TestTex.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Storage;
  5. use App\Tools\Export;
  6. class TestTex extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'test:tex';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command description';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. if(\App\Tools\Tools::isStop()){
  37. return 0;
  38. }
  39. $tex = array();
  40. $content = <<<'EOF'
  41. % 导言区
  42. \documentclass[a4paper, 12pt, fontset=ubuntu]{article} % book, report, letter
  43. \usepackage{ctex} % Use chinese package
  44. \title{\heiti 一级标题}
  45. \author{\kaishu 半闲}
  46. \date{\today}
  47. % 正文区
  48. \begin{document}
  49. \maketitle % 头部信息在正文显示
  50. \newpage
  51. \tableofcontents % 显示索引列
  52. \include{section-1.tex}
  53. \include{section-2.tex}
  54. \end{document}
  55. EOF;
  56. $tex[] = ['name'=>'main.tex','content'=>$content];
  57. $content = <<<'EOF'
  58. \section{三十位经}
  59. 住在王舍城的竹林园。
  60. 那时,三十位波婆城的比丘全是住林野者、全是常乞食者、全是穿粪扫衣者、全是但三衣者、全是尚有结缚者,他们去见世尊。
  61. \subsubsection{子章节1.1 标题}
  62. 子章节1-1 正文
  63. \subsection{子章节1.2 标题}
  64. 子章节1-2 正文
  65. EOF;
  66. $tex[] = ['name'=>'section-1.tex','content'=>$content];
  67. $content = <<<'EOF'
  68. \section{章节2 标题}
  69. 章节2 正文
  70. \subsection{子章节2.1 标题}
  71. 子章节2-1 正文
  72. \subsection{子章节2.2 标题}
  73. 子章节2-2 正文
  74. EOF;
  75. $tex[] = ['name'=>'section-2.tex','content'=>$content];
  76. $data = Export::ToPdf($tex);
  77. if($data['ok']){
  78. $filename = "export/test.pdf";
  79. $this->info($data['content-type']);
  80. Storage::disk('local')->put($filename, $data['data']);
  81. }else{
  82. $this->error($data['code'].'-'.$data['message']);
  83. }
  84. return 0;
  85. }
  86. }