동적 컨트롤로 PDF 양식 템플릿 수정 (Modify PDF Form Template with dynamic controls)


문제 설명

동적 컨트롤로 PDF 양식 템플릿 수정 (Modify PDF Form Template with dynamic controls)

여기서 빈 컨트롤이 있는 기존 PDF 양식(이전에 Open Office로 생성)을 열고 iTextSharp()를 사용하여 값을 설정하는 코드를 생성하려고 합니다. 나는 여전히 내가 해야 할 일을 하는지 알아보기 위해 iTextSharp를 테스트 중이며 지금까지 대답은 아니오입니다.

인터넷에서 찾은 내용에 따라 아래에서 내가 한 작업을 참조하세요. :

string fileNameExisting = @"PdfTemplate.pdf";
string fileNameNew = @"new.pdf";

using (var existingFileStream = new FileStream(fileNameExisting, FileMode.Open))
using (var newFileStream = new FileStream(fileNameNew, FileMode.Create))
{
     // Open existing PDF
     var pdfReader = new PdfReader(existingFileStream);

     // PdfStamper, which will create
     var stamper = new PdfStamper(pdfReader, newFileStream);

     var form = stamper.AcroFields;
     var fieldKeys = form.Fields.Keys;

    foreach (string fieldKey in fieldKeys)
    {
         bool result = form.SetField(fieldKey, "A lot of text here.");
    }

    stamper.Close();
    pdfReader.Close();
}

문제 1

iTextSharp는 Open Office(예: 텍스트 상자)의 '컨트롤' 요소만 인식합니다. PDF 템플릿에 표를 추가하려고 했지만 필드에 나타나지 않습니다. 즉, 사용하는 것이 정말 제한적입니다.

이슈 2

필드에 텍스트를 설정하면 텍스트 줄 바꿈이 없습니다. , 컨트롤의 크기는 동적이지 않으므로 텍스트가 너무 길면 모두 표시되지 않습니다. PDF는 인쇄하기 때문에 스크롤바를 사용할 수 없습니다.

해보았습니다

첫 번째 문제의 경우 Word로 PDF 양식을 만들었습니다. Open Office Writer 대신. 그러나 iTextSharp는 Word의 컨트롤을 인식하지 못합니다. 내 필드 컬렉션은 비어 있습니다.

두 번째 문제의 경우 Open Office에서 컨트롤의 모든 속성을 수정하려고 시도했으며 인터넷에서 다음을 확인했습니다. 누군가가 해결책을 가지고 있는지 확인하십시오. 하지만 내가 알기로는 AcroFields처럼 크기가 고정되어 있어서 컨트롤을 동적으로 만들 수 없고 나중에 iTextSharp로 크기를 변경할 수도 없습니다.

나는 누군가가 같은 상황을 겪었고 iTextSharp 또는 무료이든 아니든 다른 라이브러리로 나를 안내할 수 있기를 바랐습니다. 나는 내 자신의 사업을 운영하고 있기 때문에 £2000 라이선스를 감당할 수 없지만 제공해야 할 제안에 대해 열려 있습니다. 마지막 옵션은 iTextSharp를 사용하여 PDF를 처음부터 만드는 것이지만 수정만큼 빠르고 쉽게 생성할 수 없으며 PDF를 업데이트할 때마다 회사에서 코드를 변경해야 한다는 것을 의미합니다. 그 솔루션이 마음에 들지 않습니다.


참조 솔루션

방법 1:

Issue 1:

A table is not a form field. Please read the PDF specification, more specifically ISO‑32000‑1:

enter image description here

There is no such thing as a dynamic table in PDF. That is only possible in XFA (which is XML wrapped in a PDF file), but XFA is being deprecated. At iText, we'll release a (closed source) product in February 2017 for dynamic documents.

Issue 2:

The text only wraps if the field is defined as a multi‑line text field. See for instance https://developers.itextpdf.com/question/how‑get‑row‑count‑multiline‑field

The font size only adapts to the size of the field if you set the font size to 0: Set AcroField Text Size to Auto

Summarized:

Dynamic forms and PDF either require XFA in which case you need to buy Adobe LiveCycle ES (which is way above your budget), or you need to wait until iText Group releases its dynamics forms project (but that will also be more expensive than £2000).

(by nanonymousBruno Lowagie)

참조 문서

  1. Modify PDF Form Template with dynamic controls (CC BY‑SA 2.5/3.0/4.0)

#itext #C# #.net #pdf






관련 질문

iText로 가변 페이지 PDF를 생성하려고 할 때 예외 (Exception when attempting to generate variable-page PDF with iText)

Icepdf 특수 문자 렌더링 문제 (Icepdf special character rendering issue)

JAVA에서 PDF 양식 테이블 채우기 (Filling PDF form tables in JAVA)

itext를 사용하여 poi에서 차트 내보내기 (Exporting charts from poi using itext)

표 셀에 사각형을 그리는 방법은 무엇입니까? (How to draw rectangles in a Table cell?)

동적 컨트롤로 PDF 양식 템플릿 수정 (Modify PDF Form Template with dynamic controls)

itext와 같은 라이브러리로 Java 응용 프로그램을 배포하는 방법은 무엇입니까? (how to distribute a java-application with libraries such as itext?)

종이 Itext7에서 첫 번째 줄과 마지막 줄 속성을 제거합니다. (Remove the first and last lines properties in the paper Itext7)

Java에서 iText 5를 사용하여 여러 셀을 만들고 각 셀에 각 문자를 설정하는 방법 (How to create multiple cells and set each character into each cell using iText 5 in Java)

iTextSharp(또는 iText 5)를 사용하여 다른 PdfImportedPage의 배경으로 전체 PdfImportedPage를 추가하는 방법 (How to add a full PdfImportedPage as background for another PdfImportedPage with iTextSharp (or iText 5))

그래픽 텍스트 효과가 있는 텍스트 요소 (Text element with graphical text effects)

iText7을 사용하여 PDFButtonFormField에 이미지를 추가할 때 종횡비를 유지하는 방법 (How to Maintain Aspect Ratio when Adding an Image to a PDFButtonFormField using iText7)







코멘트