Webをキャプチャして変換するツール

URLとHTMLをDOCXに変換する

PHP API

HTMLまたはWebページを変換する機能を追加する intoアプリへのWord文書がこれまでになく簡単になりました GrabzItのPHP API。 ただし、開始する前に、 URLToDOCX, HTMLToDOCX or FileToDOCX メソッド。 ザ Save or SaveTo DOCXを実際に作成するには、メソッドを呼び出す必要があります。

基本オプション

DOCXとしてWebページをキャプチャすると、Webページ全体が変換されます intoa多くのページで構成できるWord文書。 以下の例では、PHP HTMLをDOCXに変換します およびWebページ int必要なパラメーターが1つだけのWord文書。

$grabzIt->URLToDOCX("https://www.tesla.com");
//Then call the Save or SaveTo method
$grabzIt->HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>");
//Then call the Save or SaveTo method
$grabzIt->FileToDOCX("example.html");
//Then call the Save or SaveTo method

カスタム識別子

にカスタム識別子を渡すことができます DOCX 次に示すメソッドを使用すると、この値はGrabzIt PHPハンドラーに返されます。 たとえば、このカスタム識別子はデータベース識別子であり、DOCXドキュメントを特定のデータベースレコードに関連付けることができます。

$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setCustomId(123456);

$grabzIt->URLToDOCX("https://www.tesla.com", $options);
//Then call the Save method
$grabzIt->Save("http://www.example.com/handler.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setCustomId(123456);

$grabzIt->HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>", $options);
//Then call the Save method
$grabzIt->Save("http://www.example.com/handler.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setCustomId(123456);

$grabzIt->FileToDOCX("example.html", $options);
//Then call the Save method
$grabzIt->Save("http://www.example.com/handler.php");

ヘッダーとフッター

一方、GrabzItは従来のWordテンプレートをサポートしていません。 Word文書にヘッダーまたはフッターを追加するときに、適用することを要求できます template 生成されるDOCXに。 このテンプレートは savedを事前に指定し、ヘッダーとフッターの内容を特別な変数とともに指定します。 以下のコード例では、ユーザーは「my template」という名前で作成したテンプレートを使用しています。

$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setTemplateId("my template");

$grabzIt->URLToDOCX("https://www.tesla.com", $options);
//Then call the Save or SaveTo method
$grabzIt->SaveTo("result.docx");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setTemplateId("my template");

$grabzIt->HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>", $options);
//Then call the Save or SaveTo method
$grabzIt->SaveTo("result.docx");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setTemplateId("my template");

$grabzIt->FileToDOCX("example.html", $options);
//Then call the Save or SaveTo method
$grabzIt->SaveTo("result.docx");

HTML要素をDOCXに変換する

divやspanなどのHTML要素を直接変換する場合 intGrabzItのPHPライブラリで使用できるWord文書。 あなたは合格しなければなりません CSSセレクター に変換するHTML要素の setTargetElement GrabzItのメソッドDOCXOptions とに提供されます。

...
<span id="Article">
<p>This is the content I am interested in.</p>
<img src="myimage.jpg">
</span>
...

この例では、次のIDを持つスパン内のすべてのコンテンツをキャプチャします。 Article。 以下に示すように、これをGrabzItに渡すことにより。

$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setTargetElement("#Article");

$grabzIt->URLToDOCX("http://www.bbc.co.uk/news", $options);
//Then call the Save or SaveTo method
$grabzIt->SaveTo("result.docx");

例に示すようにURLをWordに変換するか、HTMLをWordに変換するかは問題ではありません。 どちらもまったく同じ方法でHTML要素をターゲットにします。