透かしなしで本番環境でテストしてください。
必要な場所で動作します。
30日間、完全に機能する製品をご利用いただけます。
数分で稼働させることができます。
製品トライアル期間中にサポートエンジニアリングチームへの完全アクセス
ActivePDF Toolkit
は、PDFファイルを操作するために使用されるソフトウェアコンポーネントであり、異なるソースからPDFファイルを生成し、ヘッダー、フッター、余白、またはウォーターマークのようなプロパティを設定します。
IronPDF
は、競争力のある価格設定の<C# PDF Library>でこれらの機能も提供します。
ここでは、.NET Visual Studio プロジェクトで両方のソフトウェアコンポーネントを使用するための機能、コード例、および段階的な手順について説明します。これにより、アプリケーションに最適なものを自分で判断することができます。
Iron Softwareは、市場をリードするコンポーネントプロバイダーであり、PDFファイルの操作に使用するためにIronPDFを提供しています。 異なるフォーマットからPDFファイルを簡単に生成し、すべてのプロパティをプログラムで設定する包括的な方法。 これは、わずか数行のコードで一貫性があり、信頼性が高く、正確なPDFファイルを出力するため、開発者に好まれています。
IronPDFは、C#、.NET、VB、ASPX、ASP.NET、MVC、.NET Core用に設計されています。 Visual Studio、NuGet、Linux、Azure、Dockerなどに対応しています。
ActivePDFは、PDFファイルを処理するための多くのコンポーネントを提供するソフトウェア会社です。 単一コンポーネントであるIronPDFとは異なり、ActivePDFはPDFファイルに対して異なるソリューションを提供します。 例えば、PDFファイルのサイズを削減するには、ActivePDF Compressor
を使用できます。 HTMLソースからPDFを作成するには、ActivePDF WebGrabber
を使用します。
この記事では、IronPDFと比較するためにActivePDF WebGrabberを使用します。それでは見てみましょう:
ActivePDF WebGrabber は、URL、HTMLファイル、またはHTML文字列のようなHTMLソースからPDFファイルを生成するために特化したActivePDFの別コンポーネントです。 また、PDFファイルをニーズに合わせて作成するために、ヘッダー、フッター、マージン、透かし文字、ブックマークなどのページ属性を設定する機能も提供します。
両方のコンポーネントを並べて比較してみましょう。
IronPDF | ActivePDF |
---|---|
IronPDF converts HTML sources to PDF files. | ActivePDF converts HTML sources to PDF files. |
IronPDF supports .NET Core. | ActivePDF does not support .NET Core. |
IronPDF supports .NET 4.0 or higher. | ActivePDF supports .NET 4.6.2 or higher. |
IronPDF supports macOS. | ActivePDF does not support macOS. |
IronPDF can apply CSS to set WaterMark properties. | ActivePDF does not support CSS to set WaterMark properties. |
IronPDF can set Paper Orientation of PDF files. | ActivePDF can set Paper Orientation of PDF files. |
IronPDF provides the RenderDelay function to delay the PDF conversion. |
ActivePDF provides the TimeoutSpan function to delay the PDF conversion. |
IronPDF provides predefined functions to set Header or Footer. | ActivePDF requires setting Header and Footer by raw HTML and CSS. |
IronPDF provides a predefined function to draw a horizontal line to separate content. | ActivePDF does not provide a line to separate headers and footers. |
To save the PDF file, we can set the directory and file name in one line. | We have to set file directory and file name separately. |
Need to write fewer lines of code with a simple programming structure. | Need to write many lines of code. |
License starts from $749 . |
License starts from $1180 . |
あなたのプロジェクトにIronPDFライブラリを2種類の方法で追加することができます。
IronPDF
を検索してインストールしてください。
あるいは:
tools
に移動しますパッケージ マネージャー コンソール
を選択Install-Package IronPdf
私たちはまた、IronPDF.dllをダウンロードして、プロジェクトにリファレンスを追加することができます。
名前空間としてusing IronPdf;
を記述してIronPDF
にアクセスできる場合、それはIronPDFがプロジェクトに正常にインポートされ、使用準備が整っていることを意味します。
WebGrabber-install.exeをダウンロードし、ダウンロードファイルを選択してください。 ダウンロードが完了したら、ダウンロードしたファイルをダブルクリックしてください。 次に、以下の15日間の評価キーを使用するためのアクティベーションキーをActivePDFにリクエストしてください:001-AEALX-LC6Z5-7YD95-S3D8J-3LR25。
インストールが完了したら、次のディレクトリに移動してください:
C:\Program Files\ActivePDF\WebGrabber\bin\
このディレクトリでは、APWebGrabber.Net45.dll
ファイルを入手できます。このファイルの参照をVisual Studioプロジェクトに追加してください。
さて、using APWebGrabber;
名前空間を書いてWebGrabber
にアクセスできる場合、それはActivePDF WebGrabberがプロジェクトに正常にインポートされ、利用可能であることを意味します。
ActivePDF ドキュメント は、ActivePDF WebGrabber のインストールについて詳しく学ぶために利用できます。
これら二つのコンポーネントの導入およびインストールプロセスを見てきましたので、次に両者を使用して異なるタスクを実行しながら比較を始めます。 これにより、両方のプログラミング構造を理解し、私たちのプロジェクトにとってどちらが最適かを判断することができます。 より良い理解のために、各タスクで特定のユースケースを実行し、実装に使用されるコードを提供します。
最初の比較では、HTML文字列を使用してPDFファイルを作成し、それを対象の場所に保存するケースを取り上げます。 まず、IronPDFを使ってこのユースケースを実装し始めます:
/**
HTML String to PDF
anchor-html-string-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//HTML Source
string html = "<h1>Hello World!</h1> <h2>Welcome to IronPDF</h2> ";
//convert HTML string to PDF file
using var PDF = converter.RenderHtmlAsPdf(html);
//Save the file
PDF.SaveAs("E:/sample.pdf");
}
/**
HTML String to PDF
anchor-html-string-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//HTML Source
string html = "<h1>Hello World!</h1> <h2>Welcome to IronPDF</h2> ";
//convert HTML string to PDF file
using var PDF = converter.RenderHtmlAsPdf(html);
//Save the file
PDF.SaveAs("E:/sample.pdf");
}
'''
'''HTML String to PDF
'''anchor-html-string-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create rendering converter
Dim converter = New ChromePdfRenderer()
'HTML Source
Dim html As String = "<h1>Hello World!</h1> <h2>Welcome to IronPDF</h2> "
'convert HTML string to PDF file
Dim PDF = converter.RenderHtmlAsPdf(html)
'Save the file
PDF.SaveAs("E:/sample.pdf")
End Sub
出力:
上記のコードは、Local Disk E:
に sample.pdf
というPDFファイルを作成し、そのスクリーンショットは次のようになります:
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//HTML Source
string html = "<h1>Hello World!</h1> <h2>Welcome to ActivePDF WebGrabber</h2>";
//assign source html to WebGrabber
wg.CreateFromHTMLText = html;
//specify file directory
wg.OutputDirectory = "E:/";
// file name
wg.NewDocumentName = "sample.pdf";
//convert source HTML to PDF file
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//HTML Source
string html = "<h1>Hello World!</h1> <h2>Welcome to ActivePDF WebGrabber</h2>";
//assign source html to WebGrabber
wg.CreateFromHTMLText = html;
//specify file directory
wg.OutputDirectory = "E:/";
// file name
wg.NewDocumentName = "sample.pdf";
//convert source HTML to PDF file
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'HTML Source
Dim html As String = "<h1>Hello World!</h1> <h2>Welcome to ActivePDF WebGrabber</h2>"
'assign source html to WebGrabber
wg.CreateFromHTMLText = html
'specify file directory
wg.OutputDirectory = "E:/"
' file name
wg.NewDocumentName = "sample.pdf"
'convert source HTML to PDF file
wg.ConvertToPDF()
End Sub
次のスクリーンショットは、このコードから新しく生成されたsample.pdf
ファイルです。
この比較では、E:/
ディレクトリに存在するmyHtmlFile.html
という名前のHTMLファイルからPDFファイルを生成するケースを取り上げ、そのファイルには以下のHTMLとCSSコードがあります。
<html>
<style>
li{
font-size:x-large;
color: magenta;
font-style: italic;
}
</style>
<body>
<h1>I am Heading</h1>
<h2>Items List:</h2>
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</body>
</html>
<html>
<style>
li{
font-size:x-large;
color: magenta;
font-style: italic;
}
</style>
<body>
<h1>I am Heading</h1>
<h2>Items List:</h2>
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</body>
</html>
次に、両方のコンポーネントを使用してmyHtmlFile.html
ファイルをPDFファイルに変換します。 IronPDFから始めましょう。
/**
HTML File to PDF
anchor-html-file-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new IronPdf.ChromePdfRenderer();
//render html file to pdf
using var PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html");
//save to target location
PDF.SaveAs("E:/Sample.pdf");
}
/**
HTML File to PDF
anchor-html-file-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new IronPdf.ChromePdfRenderer();
//render html file to pdf
using var PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html");
//save to target location
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''HTML File to PDF
'''anchor-html-file-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create rendering converter
Dim converter = New IronPdf.ChromePdfRenderer()
'render html file to pdf
Dim PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html")
'save to target location
PDF.SaveAs("E:/Sample.pdf")
End Sub
以下のスクリーンショットは、上記のコードを使用して新たに生成されたSample.pdf
ファイルです。
HTMLページmyHtmlFile.html
がPDFファイルSample.pdf
に正常に変換され、CSSスタイルも適用されていることが確認できます。
IronPDFのドキュメントを読むと、.NETプロジェクトでのIronPDFの使い方について詳しくわかります。
ActivePDF WebGrabberを使用して同じタスクを実行しましょう。
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//specify file path to be converted
wg.URL = "E:/myHtmlFile.html";
//specify the directory for newly generated file
wg.OutputDirectory = "E:/";
//newly generated file name
wg.NewDocumentName = "Sample.pdf";
//convert HTML file to PDF
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//specify file path to be converted
wg.URL = "E:/myHtmlFile.html";
//specify the directory for newly generated file
wg.OutputDirectory = "E:/";
//newly generated file name
wg.NewDocumentName = "Sample.pdf";
//convert HTML file to PDF
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'specify file path to be converted
wg.URL = "E:/myHtmlFile.html"
'specify the directory for newly generated file
wg.OutputDirectory = "E:/"
'newly generated file name
wg.NewDocumentName = "Sample.pdf"
'convert HTML file to PDF
wg.ConvertToPDF()
End Sub
以下のスクリーンショットは、上記のコードを使用して新たに生成されたSample.pdf
ファイルです。
URL https://yandex.com/ を例として、そのウェブページのPDFファイルを生成したいとしましょう。 そのためには、両方のコンポーネントが機能を提供します。 まず、IronPDFを使用してどのように行うかを見てみましょう。
/**
URL to PDF
anchor-url-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//Specify URL
using var PDF = converter.RenderUrlAsPdf("https://yandex.com/");
//Save the file
PDF.SaveAs("E:/Sample.pdf");
}
/**
URL to PDF
anchor-url-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//Specify URL
using var PDF = converter.RenderUrlAsPdf("https://yandex.com/");
//Save the file
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''URL to PDF
'''anchor-url-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create rendering converter
Dim converter = New ChromePdfRenderer()
'Specify URL
Dim PDF = converter.RenderUrlAsPdf("https://yandex.com/")
'Save the file
PDF.SaveAs("E:/Sample.pdf")
End Sub
次のスクリーンショットは、上記のコードによって新たに生成されたSample.pdf
ファイルです。
IronPDFファイルの正確さがどの程度一致しているかを比較するために、URLサンプルのウェブページを訪れることができます。
では、次にActivePDF WebGrabberを使用して同じタスクを行います。
5.2. ActivePDFを使用したURL
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//specify URL
wg.URL = "https://yandex.com/";
//specify the directory for newly generated file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert specified URL webpage to PDF
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//specify URL
wg.URL = "https://yandex.com/";
//specify the directory for newly generated file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert specified URL webpage to PDF
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'specify URL
wg.URL = "https://yandex.com/"
'specify the directory for newly generated file
wg.OutputDirectory = "E:/"
'specify file name
wg.NewDocumentName = "Sample.pdf"
'convert specified URL webpage to PDF
wg.ConvertToPDF()
End Sub
以下のスクリーンショットは、上記のコードによって新しく生成されたSample.pdf
ファイルです。
この比較では、HTML文字列を使用してPDFファイルを作成し、その後、ページの中央にウォーターマークを追加します。 IronPDFから始めましょう。
IronPDFは、次の機能を提供してウォーターマークを追加します:
WatermarkPage(WaterMark HTML String, PageIndexToWaterMark, WaterMarkLocation, Opacity, Rotation, Hyperlink)
WaterMarkLocation
を使用して、次の位置にウォーターマークを設定できます:
左上
中央上部
右上
中央左
中央
右中
ボトム左
ボトムセンター
右下
上記の機能を使用してウォーターマークを設定する方法を見てみましょう。
/**
Watermark PDF
anchor-watermark-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//source html string
string html = "<h1 style='text-align:center'>WaterMark Example</h1>";
//add above string as PDF file content
using var PDF = converter.RenderHtmlAsPdf(html);
//HTML string for WaterMark
string WMStr = "<h1 style='color:red'>WaterMark</h1>";
//add WaterMark
PDF.WatermarkPage(WMStr, 0, PdfDocument.WaterMarkLocation.MiddleCenter, 100, -45, "");
//save the document
PDF.SaveAs("E:/Sample.pdf");
}
/**
Watermark PDF
anchor-watermark-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//source html string
string html = "<h1 style='text-align:center'>WaterMark Example</h1>";
//add above string as PDF file content
using var PDF = converter.RenderHtmlAsPdf(html);
//HTML string for WaterMark
string WMStr = "<h1 style='color:red'>WaterMark</h1>";
//add WaterMark
PDF.WatermarkPage(WMStr, 0, PdfDocument.WaterMarkLocation.MiddleCenter, 100, -45, "");
//save the document
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''Watermark PDF
'''anchor-watermark-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create rendering converter
Dim converter = New ChromePdfRenderer()
'source html string
Dim html As String = "<h1 style='text-align:center'>WaterMark Example</h1>"
'add above string as PDF file content
Dim PDF = converter.RenderHtmlAsPdf(html)
'HTML string for WaterMark
Dim WMStr As String = "<h1 style='color:red'>WaterMark</h1>"
'add WaterMark
PDF.WatermarkPage(WMStr, 0, PdfDocument.WaterMarkLocation.MiddleCenter, 100, -45, "")
'save the document
PDF.SaveAs("E:/Sample.pdf")
End Sub
以下のスクリーンショットは、上記のコードによって新しく生成されたSample.pdf
ファイルです。
任意の種類のウォーターマークを追加し、そのプロパティをCSSで設定することができます。 では、次にActivePDF WebGrabberを使用して同じタスクを行います。
ActivePDF WebGrabberには、IronPDFとは異なり、ウォーターマーク用の特定の機能が用意されていません。 しかし、この目的のための回避策としてAddStampText()
関数を使用できます。
AddStampText(float x, float y, string stampText);
stampTextはTextStampの実際のテキストです。
注意: ActivePDF WebGrabberは、TextStampに対するCSSスタイリングをサポートしていません。他の提供された機能を使用して設定する必要があります。
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//HTML source for Page content
string html = "<h1 style='text-align:center'>WaterMark Example</h1>";
//assign page content source
wg.CreateFromHTMLText = html;
//add text stamp as WaterMark
wg.AddStampText(270.0f, 350.0f, "WaterMark");
//specify WaterMark's font size
wg.StampFontSize = 20;
//specify WaterMark's font family
wg.StampFont = "Times New Roman";
//specify WaterMark's opacity
wg.StampFontTransparency = 1f;
//specify WaterMark's rotation
wg.StampRotation = 45.0f;
//specify WaterMark's color
wg.StampColorNET = new ADK.PDF.Color() { Red = 255, Green = 0, Blue = 0, Gray = 0 };
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert above sources to PDF file
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//HTML source for Page content
string html = "<h1 style='text-align:center'>WaterMark Example</h1>";
//assign page content source
wg.CreateFromHTMLText = html;
//add text stamp as WaterMark
wg.AddStampText(270.0f, 350.0f, "WaterMark");
//specify WaterMark's font size
wg.StampFontSize = 20;
//specify WaterMark's font family
wg.StampFont = "Times New Roman";
//specify WaterMark's opacity
wg.StampFontTransparency = 1f;
//specify WaterMark's rotation
wg.StampRotation = 45.0f;
//specify WaterMark's color
wg.StampColorNET = new ADK.PDF.Color() { Red = 255, Green = 0, Blue = 0, Gray = 0 };
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert above sources to PDF file
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'HTML source for Page content
Dim html As String = "<h1 style='text-align:center'>WaterMark Example</h1>"
'assign page content source
wg.CreateFromHTMLText = html
'add text stamp as WaterMark
wg.AddStampText(270.0F, 350.0F, "WaterMark")
'specify WaterMark's font size
wg.StampFontSize = 20
'specify WaterMark's font family
wg.StampFont = "Times New Roman"
'specify WaterMark's opacity
wg.StampFontTransparency = 1F
'specify WaterMark's rotation
wg.StampRotation = 45.0F
'specify WaterMark's color
wg.StampColorNET = New ADK.PDF.Color() With {
.Red = 255,
.Green = 0,
.Blue = 0,
.Gray = 0
}
'specify directory for newly created file
wg.OutputDirectory = "E:/"
'specify file name
wg.NewDocumentName = "Sample.pdf"
'convert above sources to PDF file
wg.ConvertToPDF()
End Sub
次のスクリーンショットは、新たに生成されたSample.pdf
ファイルのものです。
ローカルディスクEにあるmyHtmlFile.html
という名前のシンプルなウェブページがあり、幅が100%
で、黒
の色の境界線
があるとします。 これからPDFファイルを生成し、ページの余白を設定します。 IronPDFから始めましょう。
マージンを設定するには、IronPDF は ChromePdfRenderOptions
クラスを提供し、次のプロパティがあります:
MarginBottom はページの下部から余白を設定するためのプロパティです。
注: デフォルトで、IronPDFはページを読みやすくするために、左、上、右、下から20mm
の余白を設定します。 必要ない場合は、0mm
に設定できます。
/**
Set Margins
anchor-margins-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create html to PDF converter
var converter = new ChromePdfRenderer();
//specify left Margin
converter.RenderingOptions.MarginLeft = 50;
//specify top Margin
converter.RenderingOptions.MarginTop = 40;
//render html file to PDF
using var PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html");
//save to the target location
PDF.SaveAs("E:/Sample.pdf");
}
/**
Set Margins
anchor-margins-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create html to PDF converter
var converter = new ChromePdfRenderer();
//specify left Margin
converter.RenderingOptions.MarginLeft = 50;
//specify top Margin
converter.RenderingOptions.MarginTop = 40;
//render html file to PDF
using var PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html");
//save to the target location
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''Set Margins
'''anchor-margins-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create html to PDF converter
Dim converter = New ChromePdfRenderer()
'specify left Margin
converter.RenderingOptions.MarginLeft = 50
'specify top Margin
converter.RenderingOptions.MarginTop = 40
'render html file to PDF
Dim PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html")
'save to the target location
PDF.SaveAs("E:/Sample.pdf")
End Sub
以下のスクリーンショットは、上記のコードによって新しく生成されたSample.pdf
ファイルです。
PDFページは左側から50mm
、上から40
あり、左側のマージンはデフォルトで``20mm
です。 私たちは、IronPDF の ChromePdfRenderOptions
クラスを使用して、任意の側のマージンを設定するのがいかに簡単かを見ることができます。
マージンやその他のPDFファイルのプロパティを扱う方法の詳細については、PDF生成設定をご覧ください。
では、ActivePDF WebGrabber を使用してページの余白を設定します。
ページ余白を設定するために、ActivePDF WebGrabber は SetMargins()
関数を提供しており、次のように使用できます。
SetMargins(上余白, 下余白, 左余白, 右余白)
この関数を使用してページの余白を設定します:
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber()
//specify source HTML file path
wg.URL = "E:/myHtmlFile.html";
//Margins
wg.SetMargins(1, 0, 1.5f, 0);
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert HTML file to PDF
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber()
//specify source HTML file path
wg.URL = "E:/myHtmlFile.html";
//Margins
wg.SetMargins(1, 0, 1.5f, 0);
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert HTML file to PDF
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
'INSTANT VB WARNING: An assignment within expression was extracted from the following statement:
'ORIGINAL LINE: WebGrabber wg = new WebGrabber() wg.URL = "E:/myHtmlFile.html";
New WebGrabber() wg.URL = "E:/myHtmlFile.html"
Dim wg As New WebGrabber() wg.URL
'Margins
wg.SetMargins(1, 0, 1.5F, 0)
'specify directory for newly created file
wg.OutputDirectory = "E:/"
'specify file name
wg.NewDocumentName = "Sample.pdf"
'convert HTML file to PDF
wg.ConvertToPDF()
End Sub
以下のスクリーンショットは、上記のコードによって新しく生成されたSample.pdf
ファイルです。
PDFページは左側から1.5f
、上から1f
のマージンがあることがわかります。これらのコンポーネントを使用することで、必要に応じてページのマージンを簡単に設定できます。
ActivePDFで余白を設定する方法についてさらに読む。
この比較では、PDFファイルのヘッダーとフッターの設定方法を見ていきます。提供されている関数と技法を使用して、PDFページ上にカスタムヘッダーとフッターをプログラム的に印刷する方法を説明します。
IronPDFはヘッダーおよびフッターを設定するために使用できる以下のプロパティを提供します:
DrawDividerLine: ページの内容をヘッダーまたはフッターから分離する水平線を描画します。
ヘッダーまたはフッターのために、IronPDFの以下の定義済関数を中括弧{}
内で使用できます:
{pdf-title} はドキュメントのタイトルを設定します。
以下の例を見てみましょう。上記の機能を使用してページのヘッダーとフッターを設定します。
/**
Set Header Footers
anchor-headers-and-footers-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create html to PDF converter
var converter = new IronPdf.ChromePdfRenderer();
//Page Content source
string html = "<h1 style='text-align:center;'>Page Content</h2>";
//Assign source to converter
using var PDF = converter.RenderHtmlAsPdf(html);
//Add Header settings
converter.RenderingOptions.TextHeader = new TextHeaderFooter()
{
LeftText = "Header Text",
RightText = "{date} {time}",
DrawDividerLine=true,
FontSize=13
};
//Add Footer settings
converter.RenderingOptions.TextFooter = new TextHeaderFooter()
{
RightText = "Page {page} of {total-pages}",
FontSize = 12
};
//save to target location
PDF.SaveAs("E:/Sample.pdf");
}
/**
Set Header Footers
anchor-headers-and-footers-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create html to PDF converter
var converter = new IronPdf.ChromePdfRenderer();
//Page Content source
string html = "<h1 style='text-align:center;'>Page Content</h2>";
//Assign source to converter
using var PDF = converter.RenderHtmlAsPdf(html);
//Add Header settings
converter.RenderingOptions.TextHeader = new TextHeaderFooter()
{
LeftText = "Header Text",
RightText = "{date} {time}",
DrawDividerLine=true,
FontSize=13
};
//Add Footer settings
converter.RenderingOptions.TextFooter = new TextHeaderFooter()
{
RightText = "Page {page} of {total-pages}",
FontSize = 12
};
//save to target location
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''Set Header Footers
'''anchor-headers-and-footers-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create html to PDF converter
Dim converter = New IronPdf.ChromePdfRenderer()
'Page Content source
Dim html As String = "<h1 style='text-align:center;'>Page Content</h2>"
'Assign source to converter
Dim PDF = converter.RenderHtmlAsPdf(html)
'Add Header settings
converter.RenderingOptions.TextHeader = New TextHeaderFooter() With {
.LeftText = "Header Text",
.RightText = "{date} {time}",
.DrawDividerLine=True,
.FontSize=13
}
'Add Footer settings
converter.RenderingOptions.TextFooter = New TextHeaderFooter() With {
.RightText = "Page {page} of {total-pages}",
.FontSize = 12
}
'save to target location
PDF.SaveAs("E:/Sample.pdf")
End Sub
以下のスクリーンショットは、上記のコードによって新しく生成されたSample.pdf
ファイルです。
私たちはそれを確認できます
ヘッダーテキスト
はヘッダーの左側に印刷されます。DateTime
はヘッダーの右側に印刷されます。フッターの右側に、TotalPages の CurrentPage ページ
IronPDFを使用してHTMLからPDFへのプロパティ設定についてさらに読む。
それでは、ActivePDF WebGrabberを使ってページのヘッダーとフッターを設定してみましょう:
ActivePDF WebGrabber は、ヘッダーとフッターをそれぞれ設定するために HeaderHTML
および FooterHTML
プロパティを提供します。 生のHTMLはこれらのプロパティに、ページヘッダーやフッターとして渡されます。 IronPDFとは異なり、ActivePDF WebGrabberにはヘッダーおよびフッターの配置を設定するための事前定義された関数が提供されていません。そのため、次のHTMLとCSSプロパティを使用して設定する必要があります:
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//Page content source
string html = @"<h1 style='text-align:center;'>Page Content</h2>";
//assign above source to WebGrabber
wg.CreateFromHTMLText = html;
//specify Footer height
wg.FooterHeight = 0.5f;
//Add Footer setting
wg.FooterHTML = "<div style='text-align: right;'>%cp% of %tp%</div>";
//create object for datetime
DateTime now = DateTime.Now;
//specify header height
wg.HeaderHeight = 0.5f;
//Add Header setting
wg.HeaderHTML = "<div style='float: left;'>Header Text</div>";
//append Header settings
wg.HeaderHTML = $"<div style='float: right;'>{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}</div>";
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert above sources to PDF file
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//Page content source
string html = @"<h1 style='text-align:center;'>Page Content</h2>";
//assign above source to WebGrabber
wg.CreateFromHTMLText = html;
//specify Footer height
wg.FooterHeight = 0.5f;
//Add Footer setting
wg.FooterHTML = "<div style='text-align: right;'>%cp% of %tp%</div>";
//create object for datetime
DateTime now = DateTime.Now;
//specify header height
wg.HeaderHeight = 0.5f;
//Add Header setting
wg.HeaderHTML = "<div style='float: left;'>Header Text</div>";
//append Header settings
wg.HeaderHTML = $"<div style='float: right;'>{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}</div>";
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert above sources to PDF file
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'Page content source
Dim html As String = "<h1 style='text-align:center;'>Page Content</h2>"
'assign above source to WebGrabber
wg.CreateFromHTMLText = html
'specify Footer height
wg.FooterHeight = 0.5F
'Add Footer setting
wg.FooterHTML = "<div style='text-align: right;'>%cp% of %tp%</div>"
'create object for datetime
Dim now As DateTime = DateTime.Now
'specify header height
wg.HeaderHeight = 0.5F
'Add Header setting
wg.HeaderHTML = "<div style='float: left;'>Header Text</div>"
'append Header settings
wg.HeaderHTML = $"<div style='float: right;'>{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}</div>"
'specify directory for newly created file
wg.OutputDirectory = "E:/"
'specify file name
wg.NewDocumentName = "Sample.pdf"
'convert above sources to PDF file
wg.ConvertToPDF()
End Sub
次のスクリーンショットは、上記のコードから新たに生成されたSample.pdf
ファイルのものです。
ActivePDF WebGrabberでヘッダーとフッターを設定する方法についてさらに読む
DateTime
関数の使用を必要とします。Name | Detail |
---|---|
ActivePDF DocConverter | It is used to convert popular file types to and from PDF format. |
ActivePDF WebGrabber | It grabs the HTML from many sources and converts it to PDF files. |
ActivePDF DocSpace | It provides Batch Process Automation, and a user interface for display, generate, converting, manipulating, and interacting with PDF and other file formats. |
ActivePDF Toolkit | It is used to create, modify, view, extract, manipulate, and automate the document content to and from PDF files. |
ActivePDF Portal | It enables the users to view and modify PDF documents from any source in a standard web browser. |
ActivePDF CADConverter | It is used to convert CAD files into PDF. |
ActivePDF Xtractor | It is used to extract and find the text and images from PDF files. |
ActivePDF Spooler | It allows the developer to print the PDF file page on paper. |
ActivePDF Redactor | It is used to hide sensitive information from the viewer. |
ActivePDF Server | It provides the printing solution for different purposes. |
ActivePDFは、ActivePDFウェブサイトにパッケージに関する情報を提供していません。 ライセンスに関する情報を得るには、営業担当者に連絡する必要があります。 ただし、どのタイプのプロダクションライセンスを探しているのか、正確に把握しておく必要があります。 彼らは価格のリストを提供していませんが、価格は年間ライセンスで $1,180 から始まり、使用範囲によってはそれ以上になることがあり、見積もりを取得するためには詳細を明記する必要があります。
IronPDFは、ライセンスを$749 から提供し、多くのカスタマイズ可能なオプションを備えた透明な価格設定を行っています。 ご質問がございましたら、チームにお問い合わせください。
IronPDF C# ライブラリのAPIリファレンスを探索し、IronPDFのすべての機能、クラス、メソッドフィールド、名前空間、および列挙型の詳細を確認してください。
APIリファレンスを表示