itextsharp를 사용하여 기존 PDF에 양식 필드를 추가하는 방법은 무엇입니까?itextsharp를 사용하여 기존 PDF에 양식 필드를 추가하는 방법은 무엇입니까?
기존의 PDF 문서가 있는데, 사본을 만들고 새로운 문서를 작성하지 않고 양식 필드를 추가하고 싶습니다.
itextsharp를 사용하여 기존 PDF에 양식 필드를 추가하는 방법은 무엇입니까?itextsharp를 사용하여 기존 PDF에 양식 필드를 추가하는 방법은 무엇입니까?
기존의 PDF 문서가 있는데, 사본을 만들고 새로운 문서를 작성하지 않고 양식 필드를 추가하고 싶습니다.
추가 검토 후, 필드의 판결이 전복됩니다. '모양'설정이 없기 때문에 결과 문서에 필드가 표시되지 않는 스탬퍼를 평평하게 작성하면 나타납니다. 양식 평평화는 양식 필드의 추가 편집을 방지합니다. 이제 폼에 외형을 추가 할 수 있지만 더 쉬운 방법은 TextField 클래스를 사용하고 명시 적으로 '모양'객체를 설정하는 것에 대해 걱정하지 않는 것입니다.
public void ABetterWayToAddFormFieldToExistingPDF()
{
PdfReader reader = new PdfReader(@"c:\existing.pdf");
FileStream out = new FileStream(@"C:\existingPlusFields.pdf", FileMode.Create, FileAccess.Write);
PdfStamper stamp = new PdfStamper(reader, out);
TextField field = new TextField(stamp.Writer, new iTextSharp.text.Rectangle(40, 500, 360, 530), "some_text");
// add the field here, the second param is the page you want it on
stamp.AddAnnotation(field.GetTextField(), 1);
stamp.FormFlattening = true; // lock fields and prevent further edits.
stamp.Close();
}
나는 잠시 그래서 나는이 질문이 PdfStamper의 iText를 클래스의 열쇠 사용
답변 & 게시 거라고 생각이 고생. (이 복사본을 만들지 만 itext PdfCopy 클래스를 사용하여 훨씬 청소기 같아요).
public void AddFormFieldToExistingPDF()
{
PdfReader reader = new PdfReader(@"c:\existing.pdf");
FileStream out = new FileStream(@"C:\existingPlusFields.pdf", FileMode.Create, FileAccess.Write);
PdfStamper stamp = new PdfStamper(reader, out);
PdfFormField field = PdfFormField.CreateTextField(stamp.Writer, false, false, 50);
// set a field w/some position and size
field.SetWidget(new iTextSharp.text.Rectangle(40, 500, 360, 530),
PdfAnnotation.HIGHLIGHT_INVERT);
field.SetFieldFlags(PdfAnnotation.FLAGS_PRINT);
field.FieldName = "some_field";
// add the field here, the second param is the page you want it on
stamp.AddAnnotation(field, 1);
stamp.Close();
}
내 코드는 매우 유사합니다. 서명 필드는 화면에서 완벽하게 정상적으로 작동하지만 인쇄를 시도하면 종이에 빈 공간으로 표시됩니다. 이 일이 너 한테 일어 났니? – Haoest
pdfStamper를 사용하여 당신이 그것을 완료 할 수 있습니다.
PdfStamper Stamper= new PdfStamper(new PdfReader(sourcefile), File.Create(NewOutputFile));
TextField moreText = new TextField(Stamper.Writer,
new iTextSharp.text.Rectangle(20, 20, 590, 780), "moreText");
moreText.Visibility = TextField.VISIBLE_BUT_DOES_NOT_PRINT;
moreText.Text = "Use this space for any additional information";
moreText.Options = (TextField.MULTILINE);
PdfFormField Fieldtxt = moreText.GetTextField();
Stamper.AddAnnotation(Fieldtxt, n);
AddAnotation이 추가 된 필드는 아무렇게나 병합되지 않습니다. itextsharp 소스 코드의 Formflattening 속성에 대한 설명을 참조하십시오. http://sourceforge.net/p/itextsharp/code/453/tree/trunk/src/core/iTextSharp/text /pdf/PdfStamper.cs –