HTML to docx Converter 그림파일 포함

Jmnote (토론 | 기여)님의 2015년 9월 1일 (화) 18:06 판 (→‎사전 작업)
HTML to docx Converter 그림파일 포함

1 사전 작업

2 그림파일 준비

[root@zetawiki ~]# wget https://licensebuttons.net/l/by-sa/4.0/88x31.png -O /var/www/html/hello.png
... (생략)
100%[=================================================>] 1,624       --.-K/s   in 0s      

2015-09-01 18:06:16 (159 MB/s) - “/var/www/html/hello.png” saved [1624/1624]

3 test2.php 작성

<?php
require_once 'vendor/htmltodocx/phpword/PHPWord.php';
require_once 'vendor/htmltodocx/simplehtmldom/simple_html_dom.php';
require_once 'vendor/htmltodocx/htmltodocx_converter/h2d_htmlconverter.php';

$html = '<html>
<body>
	<h1>Hello 친구들</h1>
	<img src="hello.jpg"/>
	<ul>
		<li>하나</li>
		<li>둘</li>
	</ul>
	<table>
		<tr><td>1</td><td>한놈</td></tr>
		<tr><td>2</td><td>두시기</td></tr>
		<tr><td>3</td><td>석삼</td></tr>
	</table>
</body>
</html>';

$phpword = new PHPWord();
$section = $phpword->createSection();

$html_dom = new simple_html_dom();
$html_dom->load($html);
$html_arr = $html_dom->find('html',0)->children();
chdir('/');
$state = array(
  'phpword_object' => &$phpword,
  'base_root' => 'http://localhost',
  'base_path' => '/var/www/html/'
  );

htmltodocx_insert_html($section, $html_arr[0]->nodes, $state);
$objWriter = PHPWord_IOFactory::createWriter($phpword, 'Word2007');
$objWriter->save('sample.docx');

4 같이 보기