2015-10-09 45 views
1

啓用保存的PDF閱讀器選項,我開發了利用iTextSharp的使用iTextSharp的

我的代碼可編輯PDF是:

//Creating a document 
     Document document = new Document(PageSize.A4, 50, 50, 25, 25); 

     FileStream pdfFileStream = new FileStream("D:\\new.pdf", FileMode.Create); 

//Writing to PDF 
     using (PdfWriter pdfWriter = PdfWriter.GetInstance(document, pdfFileStream)) 
     { 
      //Opening the document for writing 
      document.Open(); 
      PdfContentByte cb = pdfWriter.DirectContent; 

      Paragraph para = new Paragraph("Name"); 
      document.Add(para); 

      //Creating the text box starts here ---> 
      TextField _text = new TextField(pdfWriter, new Rectangle(100, 806, 170, 790), "Name"); 
      _text.BackgroundColor = BaseColor.LIGHT_GRAY; 
      _text.Alignment = Element.ALIGN_CENTER; 
      //_text.Options = TextField.MULTILINE; 
      _text.Text = ""; 
      pdfWriter.AddAnnotation(_text.GetTextField()); 
      cb = pdfWriter.DirectContent; 

      //Creating the text box ends here ---< 

      //Creating the RadioButton group starts here ----> 

      PdfFormField _radioGroup = PdfFormField.CreateRadioButton(pdfWriter, true); 
      _radioGroup.FieldName = "Gender"; 

      string[] genders = { "Male", "Female" }; 

      RadioCheckField genderRadioCheckField; 
      PdfFormField radioGField; 

      for (int i = 0; i < genders.Length; i++) 
      { 
       genderRadioCheckField = new RadioCheckField(pdfWriter, new Rectangle(40, 806 - i * 40, 60, 788 - i * 40), null, genders[i]); 

       genderRadioCheckField.BackgroundColor = BaseColor.LIGHT_GRAY; 
       genderRadioCheckField.CheckType = RadioCheckField.TYPE_CIRCLE; 

       radioGField = genderRadioCheckField.RadioField; 
       ColumnText.ShowTextAligned(cb, Element.ALIGN_LEFT, new Phrase(genders[i], new Font(Font.FontFamily.HELVETICA, 12)), 70, 790 - i * 40, 0); 
       _radioGroup.AddKid(radioGField); 

      } 

      pdfWriter.AddAnnotation(_radioGroup); 
      cb = pdfWriter.DirectContent; 
      //Creating the RadioButton group ends here ----< 



      //Closing the document for writing 
      document.Close(); 

      Console.WriteLine("Completed"); 
      Console.ReadLine(); 

     } 

現在,代碼生成與文本字段和一個單選按鈕可編輯的PDF。

問題是:

我打開使用ADOBE READER生成的PDF文件,並在Text Field試圖挽救它輸入一些文字。

我沒有找到任何下保存選項文件菜單,但我用另存爲也嘗試 - > PDF,它顯示消息:

「這個文件不允許除非您使用Adobe Acrobat X標準版,Adobe Acrobat X pro,Adobe Acrobat X知識工作者套件,否則您將保存對其所做的任何更改,您將只保存該文檔的副本,是否繼續?

如何在Adobe PDF Reader中啓用保存選項?我的C#代碼有問題嗎?

+1

您是否嘗試過更新的Adobe Reader版本?如果我沒有記錯,Adobe現在默認允許保存已填寫的表單。 – mkl

+0

工作正常!但我已經下載了一個文件,並在該文件中編輯並保存了文檔。我不知道它是如何工作的,而不是這個。無論如何,謝謝 – Vikash

+0

爲了支持mkl,請將您的Adobe Reader升級到當前版本。從您收到的錯誤消息中可以看出,您的Adobe Reader X看起來好像已經5歲了,並且很快就會到達終點。閱讀器XI和更新版本允許保存沒有擴展權限的填寫表單。 –

回答

1

解決方案:

我以前ADOBE READER X如果我們使用iTextSharp.dll這是不支持保存選項。最後,我下載了Adobe Reader DC的最新版本,它工作正常。現在,我可以編輯和保存我的文檔。感謝所有其他答覆。

3

你想要閱讀器啓用你的PDF。閱讀器啓用涉及使用Adobe擁有的私鑰添加數字簽名。當Adobe Reader檢測到該簽名並且簽名有效時,Adobe Reader將解鎖僅在Adobe Acrobat中可用的功能(取決於您在簽署文檔時定義的使用權限)。

C#沒有問題。主要問題是您要求的功能需要訪問Adobe擁有的私鑰沒有第三方產品被授予對該密鑰的訪問權限。您只能使用Adobe軟件閱讀器啓用PDF文檔。對於iText,iTextSharp或除Adobe產品以外的任何其他軟件啓用文檔都是非法的。

總結:您所要求的功能僅在使用Adobe軟件時可用。不允許第三方供應商提供該功能(除非他們有從Adobe獲得的許可證)。

+0

我推測Reader X很快就要結束了,建議獲得當前的Reader版本應該是主要的選擇,並且將擴展權限添加到次要版本中。你怎麼看? –

-1

嘗試使用BullZIP PDF打印機打印到磁盤

+0

不再需要;正如Vikash在2015年10月9日的回答中解釋的那樣,他的問題已經在目前的Adobe Acrobat Reader DC中解決了。 – mkl