如何使用itextsharp将表插入现有PDF

问题描述:

有没有办法(使用iTextSharp)使用pdf表格,如下所示......其中:

Is there any way (using iTextSharp) to work with a pdf form like the following one ... where :

1-一些字段出现在第一个仅限页面(表单顶部)

2-仅在最后一页显示的某些字段(表单底部)

1- some fields to appear in the first page only ( Top of the form )
2- some fields to appear in the last page only ( Bottom of the form )

3-表使用C#代码添加生成表单后,前两个部分
和表我消耗多个页面(前两个之间)

3- table to be added using C# code after the form is generated with the the first two sections and the table me consume more than one page ( between the first two )

我做了以下事情:

        FillTable();
        Byte[] buffer = System.IO.File.ReadAllBytes(@"C:\Users\mahmod\Desktop\PDFform.pdf");
        string newFile = @"C:\Users\mahmod\Desktop\output.pdf";
        PdfReader reader = new PdfReader(buffer);
        PdfStamper pdfStamper = new PdfStamper(reader, new FileStream(newFile, FileMode.Open));
        table.SetTotalWidth(new float[] { 100, 100 });
        table.WriteSelectedRows(0, -1, 200, 200, pdfStamper.GetOverContent(1));
        pdfStamper.Close();

但表格会覆盖放置在区域(2)和页脚中的内容以及表格是否需要额外页面没有创建新页面....如何使表格根据需要扩展文档,最后在末尾写入区域(2)

but the table overwrites the the content placed in region(2) and the footer and if the table needs extra pages no new pages created ....how to make the table extend the document by as much pages as needed and finally writing region(2) at the end

是的,这一切都是可能的。但是,如果没有更具体的细节,我只想指出几篇希望让你入门的文章。

Yes, this is all possible. Without more specific details, however, I'm just going to point you to a couple of articles that will hopefully get you started.

  • Fill in PDF Form Fields using the Open Source iTextSharp DLL
  • How to position a table at a specific x,y coordinate