client.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. require dirname(__FILE__) . '/vendor/autoload.php';
  3. function tex2pdf($host, $request)
  4. {
  5. $client = new \Palm\Lily\V1\TexClient($host, [
  6. 'credentials' => Grpc\ChannelCredentials::createInsecure(),
  7. ]);
  8. list($response, $status) = $client->ToPdf($request)->wait();
  9. if ($status->code !== Grpc\STATUS_OK) {
  10. echo "ERROR: " . $status->code . ", " . $status->details . PHP_EOL;
  11. exit(1);
  12. }
  13. echo $response->getContentType() . '(' . strlen($response->getPayload()) . ' bytes)' . PHP_EOL;
  14. }
  15. $request = new \Palm\Lily\V1\TexToRequest();
  16. $request->getFiles()['main.tex'] = <<<'EOF'
  17. % 导言区
  18. \documentclass[a4paper, 12pt, fontset=ubuntu]{article} % book, report, letter
  19. \usepackage{ctex} % Use chinese package
  20. \title{\heiti 一级标题}
  21. \author{\kaishu 半闲}
  22. \date{\today}
  23. % 正文区
  24. \begin{document}
  25. \maketitle % 头部信息在正文显示
  26. \tableofcontents % 显示索引列
  27. \include{section-1.tex}
  28. \include{section-2.tex}
  29. \end{document}
  30. EOF;
  31. $request->getFiles()['section-1.tex'] = <<<'EOF'
  32. \section{章节1 标题}
  33. 章节1 正文
  34. \subsection{子章节1.1 标题}
  35. 子章节1-1 正文
  36. \newline This is another \verb|\newline| .
  37. \par This is a new paragraph.
  38. \newpage This is a new page.
  39. \subsection{子章节1.2 标题}
  40. 子章节1-2 正文
  41. EOF;
  42. $request->getFiles()['section-2.tex'] = <<<'EOF'
  43. \section{章节2 标题}
  44. 章节2 正文
  45. \subsection{子章节2.1 标题}
  46. 子章节2-1 正文
  47. \subsection{子章节2.2 标题}
  48. 子章节2-2 正文
  49. EOF;
  50. tex2pdf('192.168.43.100:9000', $request);