透かしなしで本番環境でテストしてください。
必要な場所で動作します。
30日間、完全に機能する製品をご利用いただけます。
数分で稼働させることができます。
製品トライアル期間中にサポートエンジニアリングチームへの完全アクセス
Humanizerは、データを扱うプロセスを簡素化し、人間に優しい形式で情報を表示する際に特に役立つ、強力で柔軟な.NETライブラリです。 日付を相対的な時間文字列に変換する(「3日前」)、単語の複数形化、数字を単語としてフォーマットする、列挙型を扱う、文字列を表示する、Pascalケースの入力文字列をカスタム説明付きの文にする、アンダースコアのある入力文字列を通常のタイトルケース文字列に変換する、長いテキストの切り詰めなど、Humanizer はC#.NETでこれらのタスクを優雅に処理するための多くのツールと拡張メソッドを提供し、非人間化された入力文字列を文に変換します。
この記事では、C# における Humanizer の詳細なチュートリアルについて説明します。 HumanizerおよびIronPDF for C# PDF Libraryを使用してPDFドキュメントを生成する方法についても話し合います。
はじめにHumanizerを使用するには、NuGet経由でライブラリをインストールする必要があります。 プロジェクト内で、次のコマンドを使用してパッケージ マネージャー コンソールでこれを実行できます:
Install-Package HumanizerInstall-Package Humanizer'INSTANT VB TODO TASK: The following line uses invalid syntax:
'Install-Package Humanizer代わりに、.NET Core CLIを使用している場合は、次のコマンドでHumanizerを追加できます:
dotnet add package Humanizerdotnet add package Humanizerインストール後、C#ファイルに適切な名前空間を含めることで、Humanizerの使用を開始できます:
using Humanizer;using Humanizer;Imports HumanizerHumanizer の最も一般的な用途の一つは、Humanize メソッドを使用して、日付や時刻を人間が読みやすい形式に変換することです。これには、期間、数値、および数量も含まれます。 これは、たとえば「2時間前」や「5日後」のような相対的な時間を表示する際に特に有用です。
DateTime pastDate = DateTime.Now.AddDays(-3);
string humanizedTime = pastDate.Humanize(); // Output: "3 days ago"
DateTime futureDate = DateTime.Now.AddHours(5);
string futureHumanizedTime = futureDate.Humanize(); // Output: "in 5 hours"DateTime pastDate = DateTime.Now.AddDays(-3);
string humanizedTime = pastDate.Humanize(); // Output: "3 days ago"
DateTime futureDate = DateTime.Now.AddHours(5);
string futureHumanizedTime = futureDate.Humanize(); // Output: "in 5 hours"Dim pastDate As DateTime = DateTime.Now.AddDays(-3)
Dim humanizedTime As String = pastDate.Humanize() ' Output: "3 days ago"
Dim futureDate As DateTime = DateTime.Now.AddHours(5)
Dim futureHumanizedTime As String = futureDate.Humanize() ' Output: "in 5 hours"Humanizer 拡張メソッドは自動的に異なる時間単位を処理し、文法的な正しさも調整します。

HumanizerはTimeSpanオブジェクトもヒューマナイズでき、期間を読みやすいフォーマットで表示するのを容易にします。
TimeSpan timeSpan = TimeSpan.FromMinutes(123);
string humanizedTimeSpan = timeSpan.Humanize(2); // Output: "2 hours, 3 minutes"TimeSpan timeSpan = TimeSpan.FromMinutes(123);
string humanizedTimeSpan = timeSpan.Humanize(2); // Output: "2 hours, 3 minutes"Dim timeSpan As TimeSpan = System.TimeSpan.FromMinutes(123)
Dim humanizedTimeSpan As String = timeSpan.Humanize(2) ' Output: "2 hours, 3 minutes"
Humanizerは、数値を人間に分かりやすい言葉に変換するためのいくつかのメソッドを提供し、序数の処理も行います。
int number = 123;
string words = number.ToWords(); // Output: "one hundred and twenty-three"int number = 123;
string words = number.ToWords(); // Output: "one hundred and twenty-three"Dim number As Integer = 123
Dim words As String = number.ToWords() ' Output: "one hundred and twenty-three"
int number = 21;
string ordinal = number.ToOrdinalWords(); // Output: "twenty-first"int number = 21;
string ordinal = number.ToOrdinalWords(); // Output: "twenty-first"Dim number As Integer = 21
Dim ordinal As String = number.ToOrdinalWords() ' Output: "twenty-first"
Humanizerは、単語を単数形と複数形の間で簡単に変換でき、数量に基づいて長いテキストを動的に生成するのに役立ちます。
string singular = "car";
string plural = singular.Pluralize(); // Output: "cars"
string word = "people";
string singularForm = word.Singularize(); // Output: "person"string singular = "car";
string plural = singular.Pluralize(); // Output: "cars"
string word = "people";
string singularForm = word.Singularize(); // Output: "person"Dim singular As String = "car"
Dim plural As String = singular.Pluralize() ' Output: "cars"
Dim word As String = "people"
Dim singularForm As String = word.Singularize() ' Output: "person"Humanizerは不規則な複数形化と単数形化も処理し、さまざまなユースケースに対して頑丈です。

Enumsは、名前付き定数のセットを表すためにC#アプリケーションで頻繁に使用されます。 Humanizerは列挙型の値を人間が読める文字列に変換できます。
MyEnum enumValue = MyEnum.FirstValue;
string humanizedEnum = enumValue.Humanize();
System.Console.WriteLine(humanizedEnum);
public enum MyEnum
{
    FirstValue,
    SecondValue
} // Output: "First value"MyEnum enumValue = MyEnum.FirstValue;
string humanizedEnum = enumValue.Humanize();
System.Console.WriteLine(humanizedEnum);
public enum MyEnum
{
    FirstValue,
    SecondValue
} // Output: "First value"Private enumValue As MyEnum = MyEnum.FirstValue
Private humanizedEnum As String = enumValue.Humanize()
System.Console.WriteLine(humanizedEnum)
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
'public enum MyEnum
'{
'	FirstValue,
'	SecondValue
'} ' Output: "First value"このメソッドは、ユーザーインターフェイスでユーザーフレンドリーなラベルを表示するのに特に有用です。

Humanizerのもう一つ便利な機能は、バイトサイズを人間が読みやすい形式に変換する能力です。大きなバイト値をKB、MB、GBなどの形式に変換します。
long bytes = 1048576;
string humanizedBytes = bytes.Bytes().Humanize(); // Output: "1 MB"long bytes = 1048576;
string humanizedBytes = bytes.Bytes().Humanize(); // Output: "1 MB"Dim bytes As Long = 1048576
Dim humanizedBytes As String = bytes.Bytes().Humanize() ' Output: "1 MB"
Humanizerは、上述した基本的なシナリオに限定されません。 それは、Truncateメソッドや複数の言語および拡張機能などの幅広い高度な機能をサポートしています。
Humanizerは、タイムゾーンを扱うアプリケーションに便利なDateTimeOffsetも処理できます。
DateTimeOffset dateTimeOffset = DateTimeOffset.Now.AddDays(-2);
string humanizedDateTimeOffset = dateTimeOffset.Humanize(); // Output: "2 days ago"DateTimeOffset dateTimeOffset = DateTimeOffset.Now.AddDays(-2);
string humanizedDateTimeOffset = dateTimeOffset.Humanize(); // Output: "2 days ago"Dim dateTimeOffset As DateTimeOffset = System.DateTimeOffset.Now.AddDays(-2)
Dim humanizedDateTimeOffset As String = dateTimeOffset.Humanize() ' Output: "2 days ago"
Humanizerは効率的に設計されていますが、他のライブラリと同様、パフォーマンスは使用方法に依存します。 高性能を必要とするアプリケーション、特に大規模なデータセットやリアルタイム処理を扱うものでは、頻繁な人為的操作が与える影響を考慮することが重要です。
IronPDFは、.NETアプリケーション向けの総合的なPDF生成および操作ライブラリです。 それにより、開発者はPDFファイルからコンテンツを簡単に作成、読み取り、編集、および抽出できるようになります。 IronPDFは、使いやすさを重視して設計されており、HTMLからPDFへの変換、ドキュメントの結合、ウォーターマークの追加など、幅広い機能を提供しています。 その汎用性と強力な機能により、C#プロジェクトでPDFドキュメントを処理する際に最適な選択肢となります。
以下の手順に従って、NuGetパッケージマネージャーを使用してIronPDFをインストールします:
プロジェクトをVisual Studioで開く:
NuGet パッケージ マネージャーを開く:
ソリューションエクスプローラーでプロジェクトを右クリックします。

IronPDFをインストールする:
NuGetパッケージマネージャーで、「参照」タブに移動します。
IronPDF を検索
検索結果からIronPDFパッケージを選択します。

これらの手順に従うことで、IronPDFがインストールされ、C#プロジェクトで使用できるようになります。その結果、強力なPDF操作機能を活用することができます。
using Humanizer;
using IronPdf;
using System;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        // Instantiate Renderer
        var renderer = new ChromePdfRenderer();
        List<string> content = GenerateHumanizedContent();
        string htmlContent = "<h1>Humanizer Examples</h1><ul>";
        // Iterate over each item in the List and add it to the HTML string
        foreach (var item in content)
        {
            htmlContent += $"<li>{item}</li>";
        }
        htmlContent += "</ul>";
        // Create a PDF from an HTML string using C#
        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        // Export to a file or stream
        pdf.SaveAs("output.pdf");
    }
    static List<string> GenerateHumanizedContent()
    {
        List<string> content = new List<string>();
        // DateTime examples
        DateTime pastDate = DateTime.Now.AddDays(-3);
        DateTime futureDate = DateTime.Now.AddHours(5);
        content.Add($"DateTime.Now: {DateTime.Now}");
        content.Add($"3 days ago: {pastDate.Humanize()}");
        content.Add($"In 5 hours: {futureDate.Humanize()}");
        // TimeSpan examples
        TimeSpan timeSpan = TimeSpan.FromMinutes(123);
        content.Add($"TimeSpan of 123 minutes: {timeSpan.Humanize()}");
        // Number examples
        int number = 12345;
        content.Add($"Number 12345 in words: {number.ToWords()}");
        content.Add($"Ordinal of 21: {21.ToOrdinalWords()}");
        // Pluralization examples
        string singular = "car";
        content.Add($"Plural of 'car': {singular.Pluralize()}");
        string plural = "children";
        content.Add($"Singular of 'children': {plural.Singularize()}");
        // Byte size examples
        long bytes = 1048576;
        content.Add($"1,048,576 bytes: {bytes.Bytes().Humanize()}");
        return content;
    }
}using Humanizer;
using IronPdf;
using System;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        // Instantiate Renderer
        var renderer = new ChromePdfRenderer();
        List<string> content = GenerateHumanizedContent();
        string htmlContent = "<h1>Humanizer Examples</h1><ul>";
        // Iterate over each item in the List and add it to the HTML string
        foreach (var item in content)
        {
            htmlContent += $"<li>{item}</li>";
        }
        htmlContent += "</ul>";
        // Create a PDF from an HTML string using C#
        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        // Export to a file or stream
        pdf.SaveAs("output.pdf");
    }
    static List<string> GenerateHumanizedContent()
    {
        List<string> content = new List<string>();
        // DateTime examples
        DateTime pastDate = DateTime.Now.AddDays(-3);
        DateTime futureDate = DateTime.Now.AddHours(5);
        content.Add($"DateTime.Now: {DateTime.Now}");
        content.Add($"3 days ago: {pastDate.Humanize()}");
        content.Add($"In 5 hours: {futureDate.Humanize()}");
        // TimeSpan examples
        TimeSpan timeSpan = TimeSpan.FromMinutes(123);
        content.Add($"TimeSpan of 123 minutes: {timeSpan.Humanize()}");
        // Number examples
        int number = 12345;
        content.Add($"Number 12345 in words: {number.ToWords()}");
        content.Add($"Ordinal of 21: {21.ToOrdinalWords()}");
        // Pluralization examples
        string singular = "car";
        content.Add($"Plural of 'car': {singular.Pluralize()}");
        string plural = "children";
        content.Add($"Singular of 'children': {plural.Singularize()}");
        // Byte size examples
        long bytes = 1048576;
        content.Add($"1,048,576 bytes: {bytes.Bytes().Humanize()}");
        return content;
    }
}Imports Humanizer
Imports IronPdf
Imports System
Imports System.Collections.Generic
Friend Class Program
	Shared Sub Main()
		' Instantiate Renderer
		Dim renderer = New ChromePdfRenderer()
		Dim content As List(Of String) = GenerateHumanizedContent()
		Dim htmlContent As String = "<h1>Humanizer Examples</h1><ul>"
		' Iterate over each item in the List and add it to the HTML string
		For Each item In content
			htmlContent &= $"<li>{item}</li>"
		Next item
		htmlContent &= "</ul>"
		' Create a PDF from an HTML string using C#
		Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
		' Export to a file or stream
		pdf.SaveAs("output.pdf")
	End Sub
	Private Shared Function GenerateHumanizedContent() As List(Of String)
		Dim content As New List(Of String)()
		' DateTime examples
		Dim pastDate As DateTime = DateTime.Now.AddDays(-3)
		Dim futureDate As DateTime = DateTime.Now.AddHours(5)
		content.Add($"DateTime.Now: {DateTime.Now}")
		content.Add($"3 days ago: {pastDate.Humanize()}")
		content.Add($"In 5 hours: {futureDate.Humanize()}")
		' TimeSpan examples
		Dim timeSpan As TimeSpan = System.TimeSpan.FromMinutes(123)
		content.Add($"TimeSpan of 123 minutes: {timeSpan.Humanize()}")
		' Number examples
		Dim number As Integer = 12345
		content.Add($"Number 12345 in words: {number.ToWords()}")
		content.Add($"Ordinal of 21: {21.ToOrdinalWords()}")
		' Pluralization examples
		Dim singular As String = "car"
		content.Add($"Plural of 'car': {singular.Pluralize()}")
		Dim plural As String = "children"
		content.Add($"Singular of 'children': {plural.Singularize()}")
		' Byte size examples
		Dim bytes As Long = 1048576
		content.Add($"1,048,576 bytes: {bytes.Bytes().Humanize()}")
		Return content
	End Function
End Class
Humanizerは、情報をユーザーフレンドリーで人間が読みやすい形式で表示するアプリケーションを作成しようとする.NET開発者にとって不可欠なライブラリです。 その幅広い機能、日付と時間のヒューマナイゼーションから数値および列挙型のフォーマットまで、はアプリケーションの使いやすさを向上させるための多用途なツールとなっています。 Humanizerを活用することで、開発者はカスタムフォーマットロジックの実装にかかる時間と労力を節約し、アプリケーションがエンドユーザーに対してデータをより効果的に伝えることを確実にすることができます。
同様に、IronPDFは包括的なPDF生成および操作機能を提供しており、C#プロジェクトでPDF文書を作成および管理するための優れた選択肢です。 HumanizerとIronPDFを組み合わせることで、.NETアプリケーションの機能とプレゼンテーションを大幅に向上させることができます。 IronPDFのライセンスについての詳細は、IronPDF Licensing Informationを参照してください。 さらに詳しく知りたい方は、HTMLからPDFへの変換に関する詳細なチュートリアルをご覧ください。