TestTex.php 2.3 KB

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