TestTex.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. $tex = array();
  37. $content = <<<'EOF'
  38. % 导言区
  39. \documentclass[a4paper, 12pt, fontset=ubuntu]{article} % book, report, letter
  40. \usepackage{ctex} % Use chinese package
  41. \title{\heiti 一级标题}
  42. \author{\kaishu 半闲}
  43. \date{\today}
  44. % 正文区
  45. \begin{document}
  46. \maketitle % 头部信息在正文显示
  47. \newpage
  48. \tableofcontents % 显示索引列
  49. \include{section-1.tex}
  50. \include{section-2.tex}
  51. \end{document}
  52. EOF;
  53. $tex[] = ['name'=>'main.tex','content'=>$content];
  54. $content = <<<'EOF'
  55. \section{三十位经}
  56. 住在王舍城的竹林园。
  57. 那时,三十位波婆城的比丘全是住林野者、全是常乞食者、全是穿粪扫衣者、全是但三衣者、全是尚有结缚者,他们去见世尊。
  58. \subsubsection{子章节1.1 标题}
  59. 子章节1-1 正文
  60. \subsection{子章节1.2 标题}
  61. 子章节1-2 正文
  62. EOF;
  63. $tex[] = ['name'=>'section-1.tex','content'=>$content];
  64. $content = <<<'EOF'
  65. \section{章节2 标题}
  66. 章节2 正文
  67. \subsection{子章节2.1 标题}
  68. 子章节2-1 正文
  69. \subsection{子章节2.2 标题}
  70. 子章节2-2 正文
  71. EOF;
  72. $tex[] = ['name'=>'section-2.tex','content'=>$content];
  73. $data = Export::ToPdf($tex);
  74. if($data['ok']){
  75. $filename = "export/test.pdf";
  76. $this->info($data['content-type']);
  77. Storage::disk('local')->put($filename, $data['data']);
  78. }else{
  79. $this->error($data['code'].'-'.$data['message']);
  80. }
  81. return 0;
  82. }
  83. }