Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用ITEXTC在现有PDF上绘制圆#_C#_Itextsharp - Fatal编程技术网

C# 使用ITEXTC在现有PDF上绘制圆#

C# 使用ITEXTC在现有PDF上绘制圆#,c#,itextsharp,C#,Itextsharp,我在现有的pdf上画圆圈时遇到了一些问题,我找到了一个在现有的pdf上添加文本的代码,我尝试将其修改为画圆圈,但结果只是一个空白页。有人知道如何解决这个问题吗 我的代码: string oldFile = @"C:\...6166-21.pdf"; string newFile = @"C:\...NEW.pdf"; // open the reader PdfReader reader = new PdfReader(oldFi

我在现有的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();

对于有效的PDF do
cb.SetColorStroke
cb.Circle
之前:一旦开始构建路径,只允许进一步的路径构建操作、剪裁路径操作或路径绘制操作。(许多观众会接受您的结果,但以后的版本可能会在这方面发生变化。)