Itext 将修改后的数据保存在pdf文件中

Itext 将修改后的数据保存在pdf文件中,itext,asp.net-web-api2,Itext,Asp.net Web Api2,我已经使用itextsharp创建了一个pdf,其中包含一些可编辑的字段,当该服务被称为pdf时,它就被创建了。但我面临的问题是,如果我在pdf中更改任何内容并下载,那么更改将不会保存。我还想通过服务器端在一个新选项卡中打开pdf 我使用的代码是: public static String[] LANGUAGES_gc = { "English", "Math", "Science" }; [HttpGet] [ODataRoute("GetPdf")] public v

我已经使用itextsharp创建了一个pdf,其中包含一些可编辑的字段,当该服务被称为pdf时,它就被创建了。但我面临的问题是,如果我在pdf中更改任何内容并下载,那么更改将不会保存。我还想通过服务器端在一个新选项卡中打开pdf

我使用的代码是:

public static String[] LANGUAGES_gc = { "English", "Math", "Science" };
    [HttpGet]
    [ODataRoute("GetPdf")]
    public void DownloadPDF()
    {
        HttpContext.Current.Response.ContentType = "application/pdf";
        HttpContext.Current.Response.AddHeader("content-disposition", "inline;filename=Example.pdf");
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

        Document doc = new Document(iTextSharp.text.PageSize.A4, 10f, 10f, 100f, 0f);
        string pdfFilePath = HttpContext.Current.Server.MapPath(".") + "/PDFFiles";
        PdfWriter wri = PdfWriter.GetInstance(doc, HttpContext.Current.Response.OutputStream);
        doc.Open();
        doc.AddAuthor("Test author");
        doc.AddCreationDate();
        PdfContentByte cb = wri.DirectContent;
        Font _bf = new Font(Font.FontFamily.HELVETICA, 6);
        PdfFormField _radioGroup = PdfFormField.CreateRadioButton(wri, true);
        _radioGroup.FieldName = "language_gc";
        Rectangle _rect;
        RadioCheckField _radioG;
        PdfFormField _radioField1;
        PdfFormField field;
        for (int i = 0; i < LANGUAGES_gc.Length; i++)
        {
            _rect = new Rectangle(46, 806 - i * 40, 60, 788 - i * 40);
            _radioG = new RadioCheckField(wri, _rect, null, LANGUAGES_gc[i]);
            _radioG.BackgroundColor = new GrayColor(0.8f);
            _radioG.BorderColor = GrayColor.BLACK;
            _radioG.CheckType = RadioCheckField.TYPE_CIRCLE;
            _radioField1 = _radioG.RadioField;
            _radioGroup.AddKid(_radioField1);              

            ColumnText.ShowTextAligned(cb, Element.ALIGN_LEFT, new Phrase(LANGUAGES_gc[i], new Font(Font.FontFamily.HELVETICA, 18)), 70, 790 - i * 40, 0);
        }
        /* Button */
        _rect = new Rectangle(300, 806, 370, 788);
      PushbuttonField button = new PushbuttonField(wri, _rect, "Buttons");
      button.BackgroundColor = new GrayColor(0.75f);
      button.BorderColor = GrayColor.GRAYBLACK;
      button.BorderWidth = 1;
      button.BorderStyle = PdfBorderDictionary.STYLE_BEVELED;
      button.TextColor = GrayColor.GRAYBLACK ;
      button.FontSize = 12;
      button.Text = "Submit";
      //button.Layout = PushbuttonField.LAYOUT_ICON_LEFT_LABEL_RIGHT;
      button.ScaleIcon = PushbuttonField.SCALE_ICON_ALWAYS;
      button.ProportionalIcon = true;
      button.IconHorizontalAdjustment = 0;

      field = button.Field;
      field.Action = PdfAction.JavaScript("this.showButtonState()", wri);
      wri.AddAnnotation(field);

    //}
    //return ms.ToArray();
        /*----------------------------------------------------*/
        wri.AddAnnotation(_radioGroup);
        wri.AddAnnotation(button.Field);
        cb = wri.DirectContent;
        doc.Close();
        HttpContext.Current.Response.Write(doc);
        HttpContext.Current.Response.End();
    }
publicstaticstring[]LANGUAGES\u gc={“英语”、“数学”、“科学”};
[HttpGet]
[ODataRoute(“GetPdf”)]
公开作废下载PDF()
{
HttpContext.Current.Response.ContentType=“application/pdf”;
HttpContext.Current.Response.AddHeader(“内容处置”,“内联;文件名=Example.pdf”);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
文档文档=新文档(iTextSharp.text.PageSize.A4、10f、10f、100f、0f);
字符串PdfilePath=HttpContext.Current.Server.MapPath(“.”+“/Pdfiles”;
PdfWriter wri=PdfWriter.GetInstance(doc,HttpContext.Current.Response.OutputStream);
doc.Open();
文件作者(“测试作者”);
AddCreationDate()文件;
PdfContentByte cb=wri.DirectContent;
Font\u bf=新字体(Font.FontFamily.HELVETICA,6);
PdfFormField _radioGroup=PdfFormField.CreateRadioButton(wri,true);
_radioGroup.FieldName=“语言\u gc”;
矩形;
放射检查场(RadioCheckField);;
Pdformfield_radioField1;
PdfFormField字段;
for(int i=0;i

有人能给我推荐解决方案吗?

让我们在这里打个比方,用一种更简单的文件类型。假设您正在向用户显示一个文本文件。他们在自己的原生.txt应用程序(记事本)中打开它并进行一些更改

您是否希望他们的更改自动传回您的服务器? 或者他们的变化被神奇地传播?当然不是。 即使它会,这似乎是记事本必须提供的功能,而不是文件创建者应该做的事情

现在,正如它所发生的那样,有一个特定的pdf文档标准正是为您的用例而存在的。本质上,文档建立了到服务器的连接,并进行同步。然而,这个标准相当模糊,没有很多观众支持它

据我所知,没有一个pdf库(包括iText)支持制作这样的文档