TestArr.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2021/6/1
  6. * Time: 17:00
  7. */
  8. require_once __DIR__.'/vendor/autoload.php';
  9. date_default_timezone_set('PRC');
  10. class Test
  11. {
  12. public function geTest()
  13. {
  14. $obj = new \TopicHtml\TopicArr\TopicHtmlArr();
  15. $topic_content = $this->getTopicContent();
  16. $topic_arr = $obj->getTopicHtmlArr($topic_content[0]);
  17. $css = (new \TopicHtml\TopicArr\TopicCss())->getTopicCss();
  18. return array($topic_arr,$css);
  19. }
  20. public function getTopicContent()
  21. {
  22. $str = '[
  23. {
  24. "id": 201511100000276,
  25. "type_id": 1,
  26. "basic_type_id": 1,
  27. "is_large_topic": 0,
  28. "type_name": "单选题",
  29. "difficulty": 1,
  30. "subject_id": 12,
  31. "create_time": 1590652297,
  32. "update_time": 1620716293,
  33. "subject_name": "物理",
  34. "is_stop": 0,
  35. "relation_topic": [],
  36. "source": "云题库",
  37. "source_title": "word:【100所名校】2018-2019学年福建省三明市第一中学高一下学期开学考试物理试题(陈明伟编辑)(陈明伟审)(10+7+0)(2020-05-28 15:18:10)",
  38. "title": "<p>钓鱼岛群岛自古以来就是中国领土,其附近海域是渔民祖祖辈辈传统的谋生渔场。我国派出海监编队到钓鱼岛海域护渔。如图所示,中国海监46船(甲)和中国海监49船(乙),在钓鱼岛领海内开展例行维权巡航。甲、乙两船并排行驶,甲船上的船员看见钓鱼岛向东移,乙船内的船员发现甲船没有动。如果以钓鱼岛为参照物,上述事实说明( )<br/><img src=\"http://tkimgs.zhixinhuixue.net/image/editor/2021/01/21/1611207638449186.png\" title=\"1611207638449186.png\" alt=\"image.png\" width=\"214\" height=\"102\" style=\"width: 214px; height: 102px;\"/></p>",
  39. "parse_content": "<p>甲船上的船员看见钓鱼岛向东移,以钓鱼岛为参照物,甲船向西运动,乙船内的船员发现甲船没有动。甲、乙两船的速度、行驶的方向应该是一样的。即甲、乙两船以相等的速度都向西运动,故选项D正确。</p>",
  40. "items": [
  41. {
  42. "type_id": 1,
  43. "options": [
  44. {
  45. "option_id": 683,
  46. "option_content": "<p>甲船向西运动,乙船不动<br/></p>",
  47. "option_correct": 0,
  48. "option_score": ""
  49. },
  50. {
  51. "option_id": 684,
  52. "option_content": "<p>乙船向西运动,甲船不动<br/></p>",
  53. "option_correct": 0,
  54. "option_score": ""
  55. },
  56. {
  57. "option_id": 685,
  58. "option_content": "<p>甲船向西运动,乙船向东运动<br/></p>",
  59. "option_correct": 0,
  60. "option_score": ""
  61. },
  62. {
  63. "option_id": 686,
  64. "option_content": "<p>甲、乙两船以相等的速度都向西运动<br/></p>",
  65. "option_correct": 1,
  66. "option_score": ""
  67. }
  68. ],
  69. "list_type": 1
  70. }
  71. ],
  72. "slave": [],
  73. "kps": [
  74. {
  75. "kp_id": 3105,
  76. "kp_name": "参考系与坐标系"
  77. }
  78. ],
  79. "specials": [],
  80. "tag": [
  81. {
  82. "tag_name": "试题来源",
  83. "type": 3,
  84. "field_name": "tag_12_43",
  85. "field_value": [
  86. "2019福建三明一中开学考"
  87. ]
  88. },
  89. {
  90. "tag_name": "年份",
  91. "type": 1,
  92. "field_name": "tag_12_52",
  93. "field_value": [
  94. 251
  95. ]
  96. },
  97. {
  98. "tag_name": "教学进度",
  99. "type": 2,
  100. "field_name": "tag_12_159",
  101. "field_value": [
  102. 782
  103. ]
  104. },
  105. {
  106. "tag_name": "物理思想",
  107. "type": 2,
  108. "field_name": "tag_12_155",
  109. "field_value": [
  110. 769
  111. ]
  112. },
  113. {
  114. "tag_name": "题型方法",
  115. "type": 2,
  116. "field_name": "tag_12_8",
  117. "field_value": [
  118. 109
  119. ]
  120. },
  121. {
  122. "tag_name": "物理学科素养",
  123. "type": 2,
  124. "field_name": "tag_12_13",
  125. "field_value": [
  126. 41
  127. ]
  128. },
  129. {
  130. "tag_name": "试题情景",
  131. "type": 2,
  132. "field_name": "tag_12_14",
  133. "field_value": [
  134. 30
  135. ]
  136. },
  137. {
  138. "tag_name": "题型类别",
  139. "type": 2,
  140. "field_name": "tag_12_11",
  141. "field_value": [
  142. 70
  143. ]
  144. },
  145. {
  146. "tag_name": "新颖等级",
  147. "type": 1,
  148. "field_name": "tag_12_55",
  149. "field_value": [
  150. 254
  151. ]
  152. },
  153. {
  154. "tag_name": "考试类型",
  155. "type": 2,
  156. "field_name": "tag_12_17",
  157. "field_value": [
  158. 84,
  159. 85,
  160. 86
  161. ]
  162. }
  163. ],
  164. "custom_column": [],
  165. "experience_degree": 0.86,
  166. "difficulty_degree": 0.86,
  167. "parse_video": "",
  168. "teacher_tips": "",
  169. "teaching_quality": "",
  170. "teaching_thought": "",
  171. "relation_method": "",
  172. "uses": {
  173. "total": 0,
  174. "school": 0,
  175. "oneself": 0
  176. }
  177. }
  178. ]';
  179. return json_decode($str, true);
  180. }
  181. }
  182. $test = new Test();
  183. list($html_content_arr,$css) = $test->geTest();
  184. $html_content = '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title>
  185. '.$css.'<br><br>
  186. </head><body>'.$html_content_arr['topic_title'].$html_content_arr['topic_option'].$html_content_arr['topic_answer'].$html_content_arr['topic_parse'].'</body></html>';
  187. $pdf_obj = new \TopicHtml\Pdf\Pdf();
  188. $pdf_obj->setPhantomjsExec('/usr/local/phantomjs-2.1.1/bin/phantomjs');//2.1
  189. //$pdf_obj->setPhantomjsExec('/usr/local/phantomjs-1.9.8/bin/phantomjs');//1.9
  190. //$pdf_obj->setPhantomjsVer('1.9');
  191. $pdf_obj->setHtmlFile(__DIR__.'/src/Pdf/tmp/test_arr.html');
  192. $pdf_obj->setPdfFile(__DIR__.'/src/Pdf/tmp/test_arr.pdf');
  193. $pdf_obj->saveHtmlFile($html_content);
  194. $rs = $pdf_obj->createPdf();
  195. //$topic_content = $test->getTopicContent();
  196. var_dump($rs);