如何使用 Itex7 和 C# 旋转图像?

How to rotate an Image using Itex7 and C#?

我正在为 iText 使用 C#SDK。作为一个简单的测试,我正在创建一个包含图像的 PDF。我想要做的是在 PDF 中旋转此图像。这是我使用的代码

PdfWriter writer = new PdfWriter("./test.pdf", new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0));
PdfDocument pdfDocument = new PdfDocument(writer);
pdfDocument.SetTagged();
Document document = new Document(pdfDocument);
Image image = new Image(ImageDataFactory.Create("google-logo.png")).SetRotationAngle(90).SetAutoScale(true);
document.Add(image);
document.Close();

然而,在生成的文件中,图像显示如下

那么如何将图像旋转 90 度?

Image#SetRotationAngle 的文档说该值必须以弧度而不是角度传递。

所以只需将 image.SetRotationAngle(90) 替换为 image.SetRotationAngle(Math.PI / 2) 就可以解决问题