【问题标题】:How to rotate an Image using Itex7 and C#?如何使用 Itex7 和 C# 旋转图像?
【发布时间】:2020-03-10 12:01:41
【问题描述】:

我正在为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 度?

【问题讨论】:

    标签: pdf .net-core itext7


    【解决方案1】:

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

    因此,只需将 image.SetRotationAngle(90) 替换为 image.SetRotationAngle(Math.PI / 2) 即可解决问题

    【讨论】:

      猜你喜欢
      • 2013-11-16
      • 1970-01-01
      • 2019-05-13
      • 1970-01-01
      • 1970-01-01
      • 2019-08-03
      • 1970-01-01
      • 1970-01-01
      • 2015-01-22
      相关资源
      最近更新 更多