IRONPDFの使用

.NET MAUIでIronPDFを使用してPDFファイルを作成する

イントロダクション

.NET マルチプラットフォーム App UI (.NET MAUI) は、C# と XAML を使用してネイティブ モバイルおよびデスクトップ アプリを作成するためのクロスプラットフォーム フレームワークです。 .NET MAUI を使用して、単一のコードベースで Android、iOS、MacOS、および Windows 上で操作できます。 .NET MAUIはオープンソースであり、Xamarin Formsの改良版です。 UIコントロールは、パフォーマンスと拡張性を向上させるために一から書き直されました。 加えて、モバイルプラットフォームからデスクトップのユースケースまで拡大しました。 Xamarin Formsを使用してクロスプラットフォームのユーザーインターフェースを作成したことがあるなら、.NET MAUIフレームワークがそれと多くの共通点を持っていることに気付くでしょう。

しかし、いくつかの違いがあります。 単一のプロジェクトで.NET MAUIフレームワークを使用してマルチプラットフォームアプリを構築できますが、必要に応じてプラットフォーム固有のコードやリソースを追加することもできます。 .NET MAUIの主な目標の一つは、アプリのロジックやUIレイアウトを可能な限り単一のコードベースで記述できるようにすることです。 .NET MAUIはすべてのプラットフォームで利用可能となり、既存のMVVMおよびXAMLパターンをサポートします。

.NET MAUIは、開発者がモバイル開発やWindowsプラットフォームなど、さまざまなプラットフォームで作業することを可能にします。

IronPDFの機能

IronPDFは、ブラウザが処理できるほとんどすべてのタスクを処理できる強力なPDFコンバーターです。 .NETライブラリは、開発者がPDFファイルの作成、読み取り、および操作を簡単に行うことができるようにします。 IronPDFはHTMLをPDFファイルに変換するためにGoogle Chromeエンジンを使用します。 他のWeb技術の中で、IronPDFはHTML、ASPX、IronPDFを使用したRazor PagesのPDFへの変換、およびMVC Viewをサポートしています。 IronPDFは、Microsoft .NETアプリケーション(ASP.NET Webアプリケーションおよび従来のWindowsアプリケーションの両方)をサポートしています。 IronPDFを使用して、魅力的なPDFドキュメントを作成することもできます。

IronPDFは、JavaScriptおよびCSSを含むHTMLファイルからPDFファイルを作成できます。

IronPDFでHTMLファイルをPDFに変換するだけでなく、画像ファイルをPDFに変換することもできます。

IronPDF はインタラクティブなPDF文書の作成に役立ち、IronPDF でインタラクティブなフォームに入力して送信するPDF文書を結合および分割するPDFからテキストや画像を抽出する、PDF文書内でテキストを検索する、PDFページを画像にラスタライズする、PDFをHTMLに変換する、そしてIronPrint を使ってPDF文書を印刷することができます。

IronPDFはURLからドキュメントを生成することができます。 HTMLのログインフォームを使用するためのIronPDFに背面ログインするためには、カスタムネットワークログイン資格情報、ユーザーエージェント、プロキシ、クッキー、HTTPヘッダー、およびフォーム変数の使用も可能です。

IronPDFは、PDFドキュメントを読み取って記入することができ、ドキュメントから画像を抽出することも可能なライブラリです。 PDFファイルにヘッダーとフッターを追加したり、テキスト、写真、より簡単にナビゲーションするためのブックマーク、ウォーターマーク、その他多くの機能をドキュメントに追加したりできます。 また、新しいドキュメントや既存のドキュメント内でページを結合および分割することもできます。 IronPDFは、Acrobatビューアを使用せずにドキュメントをPDFオブジェクトに変換することができます。 CSSファイルをPDFドキュメントに変換することも可能であり、CSSメディアタイプファイルをドキュメントに変換することもできます。

Visual Studioで新しいプロジェクトを作成

まず、Visual Studio Code と Visual Studio の両方を使用してプロジェクトを作成します。 Visual Studio Codeを使用する際には、コマンドラインツールを使用してプロジェクトタイプのテンプレートをインストールする必要があります。

Microsoft Visual Studioソフトウェアを開き、ファイルメニューに移動します。 新しいプロジェクト "を選択し、新しいプロジェクトウィンドウで".NET MAUIアプリ "を選択します。この記事では、.NET MAUI Appを使ってPDFドキュメントを生成し、適切な場所に保存します。

.NET MAUI で IronPDF を使用して PDF ファイルを作成する, 図 1: Visual Studio で新しいプロジェクトを作成

Visual Studioで新しいプロジェクトを作成する

プロジェクト名を入力し、適切なテキストボックスにファイルパスを選択してください。 次に、以下のスクリーンショットのように作成ボタンをクリックします。

.NET MAUIでIronPDFを使用してPDFファイルを作成する、図2:プロジェクトの設定

プロジェクトを構成する

Visual Studioプロジェクトは、.NET MAUI Appプラットフォームに従って、選択したアプリケーションの構造を生成します。 これで、コードを追加し、アプリケーションをビルド/実行するためにMainPage.csファイルが開かれます。

.NET MAUIでIronPDFを使用してPDFファイルを作成する、図3: MainPage.csファイルにコードを追加する

MainPage.csファイルにコードを追加する

次に、ライブラリをインストールしてコードをテストします。

IronPDFライブラリをインストールする

IronPDFライブラリは、4つの方法でダウンロードおよびインストールできます。

これらは:

  • Visual Studio を使用して。
  • Visual Studio コマンドラインの使用。
  • NuGetウェブサイトから直接ダウンロードします。
  • IronPDFのウェブサイトから直接ダウンロード。

Visual Studio を使用して

Visual Studioソフトウェアは、ソリューションにパッケージを直接インストールするためのNuGetパッケージマネージャーオプションを提供します。 以下のスクリーンショットは、NuGetパッケージマネージャーの開き方を示しています。

.NET MAUIでIronPDFを使用してPDFファイルを作成する、図4: NuGetパッケージマネージャーUIを使用して移動

NuGet パッケージ マネージャー UI に移動

これは、NuGetウェブサイトからパッケージのリストを表示するための検索ボックスを提供します。NuGetパッケージマネージャーで「IronPDF」というキーワードを検索してください。以下のスクリーンショットのように。

.NET MAUIでIronPDFを使ったPDFファイルの作成、図5: NuGetパッケージマネージャーUIからIronPdfパッケージを選択

NuGet パッケージ マネージャー UI からの IronPDF パッケージ

上記の画像では関連する検索項目がリストされています。ソリューションにパッケージをインストールするには、最初のオプションを選択してください。 .NET MAUIアプリケーションプラットフォーム、例えばAndroid、iOS、Windowsプラットフォームすべてにインストールされます。

Visual Studio コマンド ラインの使用

Visual Studioで、ツール > NuGet パッケージ マネージャー > パッケージ マネージャー コンソールに移動します。

パッケージマネージャーコンソールタブに次の行を入力してください:

Install-Package IronPdf

現在、このパッケージは現在のプロジェクトの全ての.NET MAUIプラットフォームにダウンロード/インストールされ、使用可能な状態になります。

.NET MAUIでIronPDFを使用してPDFファイルを作成する、図6: パッケージマネージャーコンソールでパッケージをインストールする

パッケージ マネージャー コンソールでパッケージをインストールする

NuGetウェブサイトから直接ダウンロード

3つ目の方法は、IronPDF NuGet リポジトリページにアクセスして、ウェブサイトから直接NuGetパッケージをダウンロードすることです。

  • 右側のメニューからダウンロードパッケージオプションを選択してください。
  • ダウンロードしたパッケージをダブルクリックしてください。 自動的にインストールされます。
  • ソリューションをリロードすると、パッケージはプロジェクトで使用可能になるはずです。

IronPDFウェブサイトから直接ダウンロード

最新のIronPDF ZIPパッケージをウェブサイトから直接ダウンロードしてください。ダウンロードが完了したら、以下の手順に従ってパッケージをプロジェクトに追加してください。

  • ソリューションウィンドウからプロジェクトの依存関係オプションを右クリックします。
  • 特定のプラットフォームを選択し、次にオプションの参照を選択し、ダウンロードした参照の場所を参照します。
  • 参照を追加するには「OK」をクリックしてください。

    .NET MAUIがサポートするすべてのプラットフォームへの言及も追加する必要があります。

.NET MAUIアプリでIronPDFを使用してPDFを作成

プロジェクトが作成されると、MainPage.xamlという自動生成されたファイルが作成されます。 これが .NET MAUI アプリケーションのユーザーインターフェースを配置する場所です。

以下のコードに従ってください。

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MAUI_PDF.MainPage"
            >

    <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            Padding="30,0"
            VerticalOptions="Center">

            <Image
                Source="dotnet_bot.png"
                SemanticProperties.Description="Cute .NET bot waving hi to you!"
                HeightRequest="200"
                HorizontalOptions="Center" />

            <Label
                Text="Welcome to IronPDF!"
                SemanticProperties.HeadingLevel="Level1"
                FontSize="32"
                HorizontalOptions="Center" />

            <Button
                x:Name="PdfBtn"
                Text="Click me to generate PDF"
                SemanticProperties.Hint="Click button to generate PDF"
                Clicked="GeneratePDF"
                HorizontalOptions="Center" />
        </VerticalStackLayout>
    </ScrollView>

</ContentPage>
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MAUI_PDF.MainPage"
            >

    <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            Padding="30,0"
            VerticalOptions="Center">

            <Image
                Source="dotnet_bot.png"
                SemanticProperties.Description="Cute .NET bot waving hi to you!"
                HeightRequest="200"
                HorizontalOptions="Center" />

            <Label
                Text="Welcome to IronPDF!"
                SemanticProperties.HeadingLevel="Level1"
                FontSize="32"
                HorizontalOptions="Center" />

            <Button
                x:Name="PdfBtn"
                Text="Click me to generate PDF"
                SemanticProperties.Hint="Click button to generate PDF"
                Clicked="GeneratePDF"
                HorizontalOptions="Center" />
        </VerticalStackLayout>
    </ScrollView>

</ContentPage>
XML

上記のコードをMainPage.xamlファイルに追加したら、MainPage.xaml.csファイルを開き、MainPageクラスに次のメソッドを含めてください:

private void GeneratePDF(object sender, EventArgs e)
{
    ChromePdfRenderer renderer = new ChromePdfRenderer();
    var doc = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF!</h1> <p>I'm using IronPDF MAUI!</p>");

    //Saves the memory stream as file.
    SaveService saveService = new SaveService();
    saveService.SaveAndView("IronPDF HTML string.pdf", "application/pdf", doc.Stream);
}
private void GeneratePDF(object sender, EventArgs e)
{
    ChromePdfRenderer renderer = new ChromePdfRenderer();
    var doc = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF!</h1> <p>I'm using IronPDF MAUI!</p>");

    //Saves the memory stream as file.
    SaveService saveService = new SaveService();
    saveService.SaveAndView("IronPDF HTML string.pdf", "application/pdf", doc.Stream);
}
Private Sub GeneratePDF(ByVal sender As Object, ByVal e As EventArgs)
	Dim renderer As New ChromePdfRenderer()
	Dim doc = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF!</h1> <p>I'm using IronPDF MAUI!</p>")

	'Saves the memory stream as file.
	Dim saveService As New SaveService()
	saveService.SaveAndView("IronPDF HTML string.pdf", "application/pdf", doc.Stream)
End Sub
$vbLabelText   $csharpLabel

GeneratePDF メソッドは、「Hello, IronPDF!」というテキストを含む新しいPDFドキュメントを生成し、指定された場所にユーザーのコンピューターに保存します。

上記のメソッドでは、新しいChromePdfRendererオブジェクトが作成され、RenderHtmlAsPdfメソッドを呼び出して、「Hello IronPDF!」という言葉を含む新しいPDFドキュメントを生成します。 HTMLマークアップの文字列から「...」を作成します。次に、ユーザーのデバイスへのファイルの保存を、SaveServiceという別のクラスに委譲する。このクラスは次のステップで作成します。

以下に完全なMainPage.xaml.csファイルがあります。 次のステップに進む前に、ファイルの内容が以下に表示されている内容と一致していることを確認してください:


// Change the namespace as desired, but make sure that all source files use this same namespace,
// or there will be errors!
namespace MAUI_IronPDF;    

// This namespace is required to make use of IronPDF functionality
using IronPdf;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void GeneratePDF(object sender, EventArgs e)
    {
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        var doc = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF!</h1> <p>I'm using IronPDF MAUI!</p>");
        //Saves the memory stream as file.
        SaveService saveService = new SaveService();
        saveService.SaveAndView("IronPDF HTML string.pdf", "application/pdf", doc.Stream);
    }
}

// Change the namespace as desired, but make sure that all source files use this same namespace,
// or there will be errors!
namespace MAUI_IronPDF;    

// This namespace is required to make use of IronPDF functionality
using IronPdf;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void GeneratePDF(object sender, EventArgs e)
    {
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        var doc = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF!</h1> <p>I'm using IronPDF MAUI!</p>");
        //Saves the memory stream as file.
        SaveService saveService = new SaveService();
        saveService.SaveAndView("IronPDF HTML string.pdf", "application/pdf", doc.Stream);
    }
}
Imports IronPdf

' Change the namespace as desired, but make sure that all source files use this same namespace,
' or there will be errors!
Namespace MAUI_IronPDF

	' This namespace is required to make use of IronPDF functionality

	Partial Public Class MainPage
		Inherits ContentPage

		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub GeneratePDF(ByVal sender As Object, ByVal e As EventArgs)
			Dim renderer As New ChromePdfRenderer()
			Dim doc = renderer.RenderHtmlAsPdf("<h1>Hello IronPDF!</h1> <p>I'm using IronPDF MAUI!</p>")
			'Saves the memory stream as file.
			Dim saveService As New SaveService()
			saveService.SaveAndView("IronPDF HTML string.pdf", "application/pdf", doc.Stream)
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

次に、プロジェクトのルートにSaveService.csという新しいクラスファイルを作成し、次のソースコードを追加します。

// Change the namespace as desired, but make sure that all source files use this same namespace,
// or there will be errors!
namespace MAUI_IronPDF
{
    // SaveService partial class declaration ... this allows a layer of abstraction
    // as we implement the save file details specially for each platform on which this app will
    // operate! 
    public partial class SaveService
    {
        public void SaveAndView(string filename, string contentType, MemoryStream stream)
        {
            SaveFile(filename, contentType, stream);
        }

        // Additional partial files will provide implementations for this method specifically.
        partial void SaveFile(string filename, string contentType, MemoryStream stream);
    }
}
// Change the namespace as desired, but make sure that all source files use this same namespace,
// or there will be errors!
namespace MAUI_IronPDF
{
    // SaveService partial class declaration ... this allows a layer of abstraction
    // as we implement the save file details specially for each platform on which this app will
    // operate! 
    public partial class SaveService
    {
        public void SaveAndView(string filename, string contentType, MemoryStream stream)
        {
            SaveFile(filename, contentType, stream);
        }

        // Additional partial files will provide implementations for this method specifically.
        partial void SaveFile(string filename, string contentType, MemoryStream stream);
    }
}
' Change the namespace as desired, but make sure that all source files use this same namespace,
' or there will be errors!
Namespace MAUI_IronPDF
	' SaveService partial class declaration ... this allows a layer of abstraction
	' as we implement the save file details specially for each platform on which this app will
	' operate! 
	Partial Public Class SaveService
		Public Sub SaveAndView(ByVal filename As String, ByVal contentType As String, ByVal stream As MemoryStream)
			SaveFile(filename, contentType, stream)
		End Sub

		' Additional partial files will provide implementations for this method specifically.
		Partial Private Sub SaveFile(ByVal filename As String, ByVal contentType As String, ByVal stream As MemoryStream)
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

ユーザーのデバイスにコンテンツを保存するための実装詳細は、各プラットフォーム(Windows、Android、MacOSなど)ごとに異なるため、アプリケーションがサポートする各デバイスタイプに合わせたプラットフォーム固有のコードを記述する必要があります。 これを可能にするために、SaveServiceを1つの部分メソッドSaveAndViewを含む部分クラス(抽象化のため)として定義します。 この後、このメソッドの実装は、ソリューションエクスプローラー内のプラットフォームフォルダにネストされているフォルダの1つ以上で、別途定義されたSaveService.csの部分クラスで定義されます(下図参照):

.NET MAUIでIronPDFを使用してPDFファイルを作成する, 図7: クロスプラットフォームを実装するフォルダ構造

クロスプラットフォームを実装するためのフォルダ構造

簡単のために、このチュートリアルでは、前述の部分ファイルをWindowsプラットフォーム専用に定義します。 Windowsプラットフォームフォルダーの下に、新しいSaveService.csファイルを作成し、以下に示すコードを含めます:

using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.UI.Popups;

namespace MAUI_IronPDF;

public partial class SaveService
{
    async partial void SaveFile(string filename, string contentType, MemoryStream stream)
    {
        StorageFile stFile;
        string extension = Path.GetExtension(filename);
        //Gets process windows handle to open the dialog in application process.
        IntPtr windowHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
        if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
        {
            //Creates file save picker to save a file.
            FileSavePicker savePicker = new();
            savePicker.DefaultFileExtension = ".pdf";
            savePicker.SuggestedFileName = filename;
            //Saves the file as PDF file.
            savePicker.FileTypeChoices.Add("PDF", new List<string>() { ".pdf" });

            WinRT.Interop.InitializeWithWindow.Initialize(savePicker, windowHandle);
            stFile = await savePicker.PickSaveFileAsync();
        }
        else
        {
            StorageFolder local = ApplicationData.Current.LocalFolder;
            stFile = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
        }
        if (stFile != null)
        {
            using (IRandomAccessStream zipStream = await stFile.OpenAsync(FileAccessMode.ReadWrite))
            {
                //Writes compressed data from memory to file.
                using Stream outstream = zipStream.AsStreamForWrite();
                outstream.SetLength(0);
                //Saves the stream as file.
                byte [] buffer = stream.ToArray();
                outstream.Write(buffer, 0, buffer.Length);
                outstream.Flush();
            }
            //Create message dialog box.
            MessageDialog msgDialog = new("Do you want to view the document?", "File has been created successfully");
            UICommand yesCmd = new("Yes");
            msgDialog.Commands.Add(yesCmd);
            UICommand noCmd = new("No");
            msgDialog.Commands.Add(noCmd);

            WinRT.Interop.InitializeWithWindow.Initialize(msgDialog, windowHandle);

            //Showing a dialog box.
            IUICommand cmd = await msgDialog.ShowAsync();
            if (cmd.Label == yesCmd.Label)
            {
                //Launch the saved file.
                await Windows.System.Launcher.LaunchFileAsync(stFile);
            }
        }
    }
}
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.UI.Popups;

namespace MAUI_IronPDF;

public partial class SaveService
{
    async partial void SaveFile(string filename, string contentType, MemoryStream stream)
    {
        StorageFile stFile;
        string extension = Path.GetExtension(filename);
        //Gets process windows handle to open the dialog in application process.
        IntPtr windowHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
        if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
        {
            //Creates file save picker to save a file.
            FileSavePicker savePicker = new();
            savePicker.DefaultFileExtension = ".pdf";
            savePicker.SuggestedFileName = filename;
            //Saves the file as PDF file.
            savePicker.FileTypeChoices.Add("PDF", new List<string>() { ".pdf" });

            WinRT.Interop.InitializeWithWindow.Initialize(savePicker, windowHandle);
            stFile = await savePicker.PickSaveFileAsync();
        }
        else
        {
            StorageFolder local = ApplicationData.Current.LocalFolder;
            stFile = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
        }
        if (stFile != null)
        {
            using (IRandomAccessStream zipStream = await stFile.OpenAsync(FileAccessMode.ReadWrite))
            {
                //Writes compressed data from memory to file.
                using Stream outstream = zipStream.AsStreamForWrite();
                outstream.SetLength(0);
                //Saves the stream as file.
                byte [] buffer = stream.ToArray();
                outstream.Write(buffer, 0, buffer.Length);
                outstream.Flush();
            }
            //Create message dialog box.
            MessageDialog msgDialog = new("Do you want to view the document?", "File has been created successfully");
            UICommand yesCmd = new("Yes");
            msgDialog.Commands.Add(yesCmd);
            UICommand noCmd = new("No");
            msgDialog.Commands.Add(noCmd);

            WinRT.Interop.InitializeWithWindow.Initialize(msgDialog, windowHandle);

            //Showing a dialog box.
            IUICommand cmd = await msgDialog.ShowAsync();
            if (cmd.Label == yesCmd.Label)
            {
                //Launch the saved file.
                await Windows.System.Launcher.LaunchFileAsync(stFile);
            }
        }
    }
}
Imports Windows.Storage
Imports Windows.Storage.Pickers
Imports Windows.Storage.Streams
Imports Windows.UI.Popups

Namespace MAUI_IronPDF

	Partial Public Class SaveService
		Private Async Sub SaveFile(ByVal filename As String, ByVal contentType As String, ByVal stream As MemoryStream)
			Dim stFile As StorageFile
			Dim extension As String = Path.GetExtension(filename)
			'Gets process windows handle to open the dialog in application process.
			Dim windowHandle As IntPtr = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle
			If Not Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons") Then
				'Creates file save picker to save a file.
				Dim savePicker As New FileSavePicker()
				savePicker.DefaultFileExtension = ".pdf"
				savePicker.SuggestedFileName = filename
				'Saves the file as PDF file.
				savePicker.FileTypeChoices.Add("PDF", New List(Of String)() From {".pdf"})

				WinRT.Interop.InitializeWithWindow.Initialize(savePicker, windowHandle)
				stFile = Await savePicker.PickSaveFileAsync()
			Else
				Dim local As StorageFolder = ApplicationData.Current.LocalFolder
				stFile = Await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting)
			End If
			If stFile IsNot Nothing Then
				Using zipStream As IRandomAccessStream = Await stFile.OpenAsync(FileAccessMode.ReadWrite)
					'Writes compressed data from memory to file.
					Using outstream As Stream = zipStream.AsStreamForWrite()
						outstream.SetLength(0)
						'Saves the stream as file.
						Dim buffer() As Byte = stream.ToArray()
						outstream.Write(buffer, 0, buffer.Length)
						outstream.Flush()
					End Using
				End Using
				'Create message dialog box.
				Dim msgDialog As New MessageDialog("Do you want to view the document?", "File has been created successfully")
				Dim yesCmd As New UICommand("Yes")
				msgDialog.Commands.Add(yesCmd)
				Dim noCmd As New UICommand("No")
				msgDialog.Commands.Add(noCmd)

				WinRT.Interop.InitializeWithWindow.Initialize(msgDialog, windowHandle)

				'Showing a dialog box.
				Dim cmd As IUICommand = Await msgDialog.ShowAsync()
				If cmd.Label = yesCmd.Label Then
					'Launch the saved file.
					Await Windows.System.Launcher.LaunchFileAsync(stFile)
				End If
			End If
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

MAUIアプリケーションをビルドして実行します。 以下に示すインターフェースを含むウィンドウが表示されます。

IronPDFを使用した.NET MAUIでのPDFファイルの作成、図8: MAUIアプリのUI

MAUIアプリのUI

「Generate PDF」ボタンをクリックしてください。 数秒後に、生成されたPDFファイルの保存場所を選択するポップアップが表示されます。

.NET MAUIでIronPDFを使用してPDFファイルを作成する、図9: PDFファイルを保存する場所を選択

PDFファイルを保存する場所を選択してください

結論

IronPDFは、PDFを生成、読み取り、編集、フォーマットすることができる、最も一般的に使用されているPDF変換ライブラリの1つです。 IronPDFライブラリは、指定されたURLをPDFファイルに変換するためのブラウザエンジンを提供し、HTML文字列にCSSを追加してPDFファイルに変換することができ、さらにPDFフォームに入力することもできるなど、多くの利点と機能を提供します。 IronPDFのすべての機能が1つのライブラリに含まれています。

IronPDFは、さまざまな価格構造があります。 IronPDFの基本価格は$749からです。 製品サポートとアップデートは、1年間の料金で利用可能です。 ロイヤリティフリーの再配布カバレッジも追加オプションとして購入できます。

要約すると、IronPDFは優れたパフォーマンスと多くの機能を提供しており、PDFを扱う開発者に推奨されます。 .NET MAUIなどのユニバーサルプラットフォームをサポートしています。 それは、IronPDFライブラリの広範な機能とその多くの特徴を完全に活用するための優れたサポートとドキュメントも付属しています。

チペゴ
ソフトウェアエンジニア
チペゴは優れた傾聴能力を持ち、それが顧客の問題を理解し、賢明な解決策を提供する助けとなっています。彼は情報技術の学士号を取得後、2023年にIron Softwareチームに加わりました。現在、彼はIronPDFとIronOCRの2つの製品に注力していますが、顧客をサポートする新しい方法を見つけるにつれて、他の製品に関する知識も日々成長しています。Iron Softwareでの協力的な生活を楽しんでおり、さまざまな経験を持つチームメンバーが集まり、効果的で革新的な解決策を提供することに貢献しています。チペゴがデスクを離れているときは、良い本を楽しんだり、サッカーをしていることが多いです。
< 以前
BlazorチュートリアルでPDFファイルを作成
次へ >
C#で画像をPDFに変換する方法 [コード例チュートリアル]