テキストボックスフィールドでのテキストの均等配置

Contents
[ ]

実装の詳細

FormEditorクラスは、Aspose.Pdf.Facades名前空間でPDFフォームフィールドを装飾する機能を提供します。テキストボックスフィールド内のテキストを均等配置する必要がある場合は、FormFieldFacade列挙型のAlignJustified値を使用し、FormEditor.DecorateFieldメソッドを呼び出すことで簡単に実現できます。以下の例では、まずFormクラスのFillFieldメソッドを使用してテキストボックスフィールドを入力します。その後、FormEditorクラスを使用してテキストボックスフィールド内のテキストを均等配置します。以下のコードスニペットは、テキストボックスフィールドでテキストを均等配置する方法を示しています。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void JustifyTextInTextboxField()
{
    // The path to the documents directory 
    var dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();
    // Open PDF document
    using (var source = File.Open(dataDir + "JustifyText.pdf", FileMode.Open))
    {
        using (var ms = new MemoryStream())
        {
            // Create Form Object
            var form = new Aspose.Pdf.Facades.Form();
            // Bind PDF document
            form.BindPdf(source);
            // Fill Text Field
            form.FillField("Text1", "Thank you for using Aspose");
            // Save PDF document in Memory Stream
            form.Save(ms);
            ms.Seek(0, SeekOrigin.Begin);

            using (var dest = new FileStream(dataDir + "JustifyText_out.pdf", FileMode.Create))
            {
                // Create formEditor Object
                using (var formEditor = new Aspose.Pdf.Facades.FormEditor())
                {
                    // Open PDF from memory stream
                    formEditor.BindPdf(ms);
                    // Set Text Alignment as Justified
                    formEditor.Facade.Alignment = Aspose.Pdf.Facades.FormFieldFacade.AlignJustified;
                    // Decorate form field
                    formEditor.DecorateField();
                    // Save PDF document
                    formEditor.Save(dest);
                }
            }
        }
    }
}

PDFでは均等配置がサポートされていないため、テキストボックスフィールドにテキストを入力すると、テキストは左揃えになります。ただし、フィールドがアクティブでない場合、テキストは均等配置されます。