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

URLとHTMLをDOCXに変換する

Ruby API

HTMLまたはWebページを変換する機能を追加する intoアプリケーションへのWord文書がこれまでになく簡単になりました GrabzItのRuby API。 ただし、開始する前に、 url_to_docx, html_to_docx or file_to_docx メソッド save or save_to DOCXを実際に作成するには、メソッドを呼び出す必要があります。

基本オプション

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

grabzItClient.url_to_docx("https://www.tesla.com")
# Then call the save or save_to method
grabzItClient.html_to_docx("<html><body><h1>Hello World!</h1></body></html>")
# Then call the save or save_to method
grabzItClient.file_to_docx("example.html")
# Then call the save or save_to method

カスタム識別子

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

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.customId = "123456"

grabzItClient.url_to_docx("https://www.tesla.com", options)
# Then call the save method
grabzItClient.save("http://www.example.com/handler/index")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.customId = "123456"

grabzItClient.html_to_docx("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the save method
grabzItClient.save("http://www.example.com/handler/index")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.customId = "123456"

grabzItClient.file_to_docx("example.html", options)
# Then call the save method
grabzItClient.save("http://www.example.com/handler/index")

ヘッダーとフッター

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

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.templateId = "my template"

grabzItClient.url_to_docx("https://www.tesla.com", options)
# Then call the save or save_to method
grabzItClient.save_to("result.docx")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.templateId = "my template"

grabzItClient.html_to_docx("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the save or save_to method
grabzItClient.save_to("result.docx")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.templateId = "my template"

grabzItClient.file_to_docx("example.html", options)
# Then call the save or save_to method
grabzItClient.save_to("result.docx")

HTML要素をDOCXに変換する

divやspanなどのHTML要素を直接変換する場合 intGrabzItのRuby GemでできるWord文書。 あなたは合格しなければなりません CSSセレクター に変換するHTML要素の targetElement 方法 DOCXOptions とに提供されます。

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

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

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.targetElement = "#Article"

grabzItClient.url_to_docx("http://www.bbc.co.uk/news", options)
# Then call the save or save_to method
grabzItClient.save_to("result.docx")