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

WebページとHTMLをPDFに変換する

Python API

WebページとHTMLをPDFに変換する場合 GrabzItのPython API 次の機能を提供します integrate GrabzIt intoシステムをできるだけ簡単に。 ただし、開始する前に、 URLToPDF, HTMLToPDF or FileToPDF メソッド Save or SaveTo PDFスクリーンショットを取得するには、メソッドを呼び出す必要があります。

基本オプション

多くの場合、ウェブページを変換するとき intWebページ全体を表すために、PDFドキュメントの多くのページが作成されます。 Webページを変換するために必要なパラメーターは1つだけです intPDF文書または HTMLをPDFに変換 以下の例に示すように。

grabzIt.URLToPDF("https://www.tesla.com")
# Then call the Save or SaveTo method
grabzIt.HTMLToPDF("<html><body><h1>Hello World!</h1></body></html>")
# Then call the Save or SaveTo method
grabzIt.FileToPDF("example.html")
# Then call the Save or SaveTo method

カスタム識別子

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

from GrabzIt import GrabzItPDFOptions
from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItPDFOptions.GrabzItPDFOptions()
options.customId = "123456"

grabzIt.URLToPDF("https://www.tesla.com", options)
# Then call the Save method
grabzIt.Save("http://www.example.com/handler.py")
from GrabzIt import GrabzItPDFOptions
from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItPDFOptions.GrabzItPDFOptions()
options.customId = "123456"

grabzIt.HTMLToPDF("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the Save method
grabzIt.Save("http://www.example.com/handler.py")
from GrabzIt import GrabzItPDFOptions
from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItPDFOptions.GrabzItPDFOptions()
options.customId = "123456"

grabzIt.FileToPDF("example.html", options)
# Then call the Save method
grabzIt.Save("http://www.example.com/handler.py")

ヘッダーとフッター

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

ヘッダーまたはフッターの上部マージンまたは下部マージンが十分に大きくない場合、PDFには表示されません。 次の例では、十分なスペースを確保するために、上部と下部のマージンを20に設定しています。

from GrabzIt import GrabzItPDFOptions
from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItPDFOptions.GrabzItPDFOptions()
options.marginTop = 20
options.marginBottom = 20
options.templateId = "my template"

grabzIt.FileToPDF("example.html", options)
# Then call the Save or SaveTo method
grabzIt.SaveTo("result.pdf")

HTML要素をPDFに変換

divやspanなどのHTML要素を直接変換する場合 intGrabzItのPythonライブラリで使用できるPDFドキュメント。 あなたは合格しなければなりません CSSセレクター に変換するHTML要素の targetElement パラメータに一致する最初のデバイスのリモートコントロール URL を返します。

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

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

from GrabzIt import GrabzItPDFOptions
from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItPDFOptions.GrabzItPDFOptions()
options.targetElement = "#Article"

grabzIt.URLToPDF("http://www.bbc.co.uk/news", options)
# Then call the Save or SaveTo method
grabzIt.SaveTo("result.pdf")

HTML要素をターゲットにするときにPDFがトリミングされる方法 これらの手法を使用して制御.