本操作指南解释了使用 C#** 在 PDF 中旋转文本的过程。它提供了有关环境配置、待办事项步骤和可运行示例代码的详细信息,以使用 C# 在 Acrobat 中旋转文本**。您还将学习设置文本片段的不同属性以及设置旋转角度。
使用 C# 旋转 PDF 中文本的步骤
- 建立环境以添加 Aspose.PDF for .NET 以旋转文本
- 使用 Document class 对象创建一个新的 PDF 并向其添加一个新页面
- 创建一个 TextFragment 对象并设置位置、字体和旋转角度等参数
- 使用上面新添加的页面创建一个 TextBuilder 对象
- 将文本片段附加到文本构建器对象
- 将生成的 PDF 文件保存在其中包含旋转文本的磁盘上
这些步骤描述了使用 C#** **旋转 PDF 上的文本的操作。它突出显示了示例代码中使用的所有必要类、方法和属性,例如用于创建 PDF 文件的 Document 类、用于创建文本和设置其属性的 TextFragment 类以及最终在 PDF 中添加旋转文本的 TextBuilder 类。
使用 C# 在 Adobe Acrobat 中旋转文本的代码
using Aspose.Pdf; | |
using Aspose.Pdf.Text; | |
namespace AsposeProjects | |
{ | |
class Program | |
{ | |
static void Main(string[] args) // Main function to rotate text in a PDF using C# | |
{ | |
// Initialize license | |
License lic = new License(); | |
lic.SetLicense("Aspose.Total.lic"); | |
// Instantiate a document object to add rotated text | |
Document pdfDocument = new Document(); | |
// Add a new page and get its reference | |
Page pdfPage = (Page)pdfDocument.Pages.Add(); | |
// Create a text fragment | |
TextFragment fragment = new TextFragment("Sample rotated text"); | |
fragment.Position = new Position(250, 550); | |
// Set Font properties | |
fragment.TextState.FontSize = 14; | |
fragment.TextState.Font = FontRepository.FindFont("Arial"); | |
// Set rotation angle | |
fragment.TextState.Rotation = 60; | |
// Create a TextBuilder object | |
TextBuilder builder = new TextBuilder(pdfPage); | |
// Add the text fragment to the PDF page | |
builder.AppendText(fragment); | |
// Save the document | |
pdfDocument.Save("RotatedText.pdf"); | |
System.Console.WriteLine("Text rotated successfully"); | |
} | |
} | |
} |
此代码演示了使用 C#* 在 Adobe 中*旋转文本的过程,其中 TextFragment 类用于创建文本元素并设置其属性,例如通过提供 XIndent 和 YIndent 设置位置,通过大小和字体名称设置字体,以及旋转由角度设置。 TextBuilder 类用于追加文本片段以及在需要时向文档追加段落。
这篇文章教会了我们在 PDF 中添加和旋转文本。如果您想了解在 PDF 中添加水印的过程,请参阅 如何在C#中为PDF添加水印 上的文章。