WebページとHTMLをPDFに変換する場合 GrabzItのASP.NET API 次の機能を提供します integrate GrabzIt intoシステムをできるだけ簡単に。 ただし、開始する前に、 URLToPDF, HTMLToPDF or FileToPDF メソッド Save or SaveTo PDFスクリーンショットを取得するには、メソッドを呼び出す必要があります。
PDFスクリーンショットは、Webページ全体をキャプチャし、元のWebページと同じ長さの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 ASP.NETハンドラーに返されます。 たとえば、このカスタム識別子はデータベース識別子であり、スクリーンショットを特定のデータベースレコードに関連付けることができます。
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); PDFOptions options = new PDFOptions(); options.CustomId = "123456"; grabzIt.URLToPDF("https://www.tesla.com", options); //Then call the Save method grabzIt.Save("http://www.example.com/Home/Handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); PDFOptions options = new PDFOptions(); 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/Home/Handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); PDFOptions options = new PDFOptions(); options.CustomId = "123456"; grabzIt.FileToPDF("example.html", options); //Then call the Save method grabzIt.Save("http://www.example.com/Home/Handler");
PDFスクリーンショットを作成するとき、特定のアプリケーションを適用することを宣言できます template 生成されたPDFへ。 このテンプレートは事前に作成する必要があり、ヘッダーとフッターのコンテンツと特別な変数を定義します。 以下のサンプルコードでは、ユーザーはPDFテンプレート「my template」を適用しています。
ヘッダーまたはフッターの上部マージンまたは下部マージンが十分に大きくない場合、PDFには表示されません。 次の例では、十分なスペースを確保するために、上部と下部のマージンを20に設定しています。
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); PDFOptions options = new PDFOptions(); options.MarginTop = 20; options.MarginBottom = 20; options.TemplateId = "my template"; grabzIt.URLToPDF("https://www.tesla.com", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.pdf");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); PDFOptions options = new PDFOptions(); options.MarginTop = 20; options.MarginBottom = 20; options.TemplateId = "my template"; grabzIt.HTMLToPDF("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.pdf");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); PDFOptions options = new PDFOptions(); 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");
divやspanなどのHTML要素を直接変換する場合 intGrabzItのASP.NETライブラリで使用できる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に渡します。
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); PDFOptions options = new PDFOptions(); 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がトリミングされる方法 これらの手法を使用して制御.