c# - 使用 itextsharp c# 在现有 PDF 上绘制圆圈

标签 c# itext

我在现有 pdf 上绘制圆圈时遇到了一些麻烦,我找到了在现有 PDF 上添加文本的代码,我尝试对其进行调整以绘制圆圈,但结果只是一个空白页有人知道如何解决这个问题吗?

我的代码:

        string oldFile = @"C:\...6166-21.pdf";
        string newFile = @"C:\...NEW.pdf";

        // open the reader
        PdfReader reader = new PdfReader(oldFile);
        Rectangle size = reader.GetPageSizeWithRotation(1);
        Document document = new Document(size);

        FileStream fs = new FileStream(newFile, FileMode.Create, FileAccess.Write);
        PdfWriter writer = PdfWriter.GetInstance(document, fs);
        document.Open();

        // the pdf content
        PdfContentByte cb = writer.DirectContent;

        cb.Circle(150f, 150f, 50f);
        cb.SetColorStroke(iTextSharp.text.BaseColor.GREEN);

        // create the new page and add it to the pdf
        PdfImportedPage page = writer.GetImportedPage(reader, 1);
        cb.AddTemplate(page, 0, 0);

        // close the streams and voilá the file should be changed :)
        document.Close();
        fs.Close();
        writer.Close();
        reader.Close();

最佳答案

你忘了添加 cb.Stroke();

请这样尝试:

cb.SetColorStroke(iTextSharp.text.BaseColor.GREEN);
cb.Circle(150f, 150f, 50f);
cb.Stroke();

关于c# - 使用 itextsharp c# 在现有 PDF 上绘制圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30194856/

相关文章:

iTextPDF 库 - 找不到类 "com.itextpdf.text.pdf.PdfAWriter"

c# - 如何从类的实例访问嵌套类?

c# - 使用模式 "MM/dd/yyyy hh:mm:ss"将字符串转换为 DateTime

c# - 无法使用绑定(bind)源刷新数据 GridView

java - 无法使用itext从图像中获取absoluteX和absoluteY

java - itextpdf 生成损坏的链接

c# - 在 Asp.Net Core 中进行模型验证之前修剪字符串

c# - 如何使用windows服务打印pdf文件

java - Itext Java 11 : Illegal reflective access by com. itextpdf.io.source.ByteBufferRandomAccessSource$1

c# - 使用基于 iTextSharp 的模板创建 PDF 文档