C# 使用iTextSharp创建的批注未显示

C# 使用iTextSharp创建的批注未显示,c#,pdf,itextsharp,C#,Pdf,Itextsharp,我有一个空白的1页MS Word文档的PDF。我想在其中添加一个文本框。代码如下: void addAnnotation() { string filename = @"C:\Users\userID\Documents\Visual Studio 2013\Projects\PDFConverterTester\TestAddSrc.pdf"; string destFile = @"C:\Users\userID\Documents\Visual Studio 2013\Pr

我有一个空白的1页MS Word文档的PDF。我想在其中添加一个文本框。代码如下:

void addAnnotation()
{
    string filename = @"C:\Users\userID\Documents\Visual Studio 2013\Projects\PDFConverterTester\TestAddSrc.pdf";
    string destFile = @"C:\Users\userID\Documents\Visual Studio 2013\Projects\PDFConverterTester\TestAddDest.pdf";
    PdfReader pdfReader = new PdfReader(filename);
    FileStream stream = new FileStream(destFile, FileMode.Create);
    PdfStamper pdfStamper = new PdfStamper(pdfReader, stream);

    iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(100,100, 100, 100);
    PdfWriter pdfWriter = pdfStamper.Writer;
    PdfAnnotation annot = PdfAnnotation.CreateStamp(pdfWriter, rect, "XYZABC add rect", "new rectangle");
    pdfStamper.AddAnnotation(annot, 1);
    pdfStamper.Close();
}
当我打开
TestAddDest.pdf
时,它是空白的,就像源pdf一样,并且文件大小相同,因此我假设没有添加注释。如何添加此文本框

编辑:

资料来源PDF:


目标PDF:

PDF为空的原因是
矩形
为零宽度和零高度:

iTextSharp.text.Rectangle rect=新建 iTextSharp.text.Rectangle(100100100100)

在该行上放置断点,或者:

Console.WriteLine("W: {0}, H: {1}", rect.Width, rect.Height);
输出:

W:0,H:0

尝试这样做,将
矩形
放置在页面顶部:

Rectangle rect = new Rectangle(20, 700, 400, 776);
目的地PDF:


当我针对空白PDF运行代码时,我会在新文件中得到预期的注释。你能把你的前后PDF发到某个地方让我们检查吗?@ChrisHaas,完成,请参见编辑。