나는 직면하고있다
인덱스 배열의 범위를 벗어난 것입니다
을 PdfPTable
사용하여 문서에 추가 하는 동안 오류가 발생했습니다 iTextShrap
. 아래는 코드입니다
Document myDocument = new Document(PageSize.A3.Rotate());
PdfWriter.GetInstance(myDocument, new FileStream("payslip.pdf", FileMode.Create));
myDocument.Open();
PdfPTable table = new PdfPTable(35);
table.TotalWidth = myDocument.PageSize.Width - 80f;
table.LockedWidth = true;
List<PdfPCell> headRow = new List<PdfPCell>();
PdfPCell contractor = new PdfPCell(new Phrase("XXXXXXXXXXXXX"));
contractor.Colspan = 5;
headRow.Add(contractor);
PdfPCell workType = new PdfPCell(new Phrase("Refractory Works"));
workType.Colspan = 5;
headRow.Add(workType);
PdfPCell supervisor = new PdfPCell(new Phrase("XXXXXXXXXXXXXX"));
supervisor.Colspan = 4;
headRow.Add(supervisor);
PdfPCell paySlipHead = new PdfPCell(new Phrase("XXXXXXXXXXXXXXXX"));
paySlipHead.Colspan = 10;
headRow.Add(paySlipHead);
PdfPCell paySlipMonth = new PdfPCell(new Phrase("XXXXXXX"));
paySlipMonth.Colspan = 2;
headRow.Add(paySlipMonth);
PdfPCell blank = new PdfPCell(new Phrase(""));
blank.Colspan = 9;
headRow.Add(blank);
PdfPRow rw = new PdfPRow(headRow.ToArray());
table.Rows.Add(rw);
myDocument.Add(table);
나는 무엇이 잘못되고 있는지 전혀 모른다. 제안하십시오
문제는 문서에 설명 된 내용, 특히 내가 작성한 부분을 존중하지 않기 때문에 발생합니다.
거기의
PdfPRow
에서 개체com.itextpdf.text.pdf
패키지는,하지만 당신이 직접 해결하기 위해 안된다. iText는이 클래스를 내부적으로 사용하여 동일한 행에 속하는 셀을 저장합니다. (iText in Action-Second Edition, 섹션 4.1.1 "첫 번째 테이블", p94)
기본 예제를 살펴 보는 데 시간을 할애하지 않는다면 작동하는 코드를 작성할 수 있다고 기 대해서는 안됩니다.
SimpleTable3 예제를 살펴보십시오 . 이 예에서는 PdfPRow
. 대신 PdfPCell
객체를 다음과 PdfPTable
같이 추가 합니다 .
PdfPTable table = new PdfPTable(35);
table.setTotalWidth(document.getPageSize().getWidth() - 80);
table.setLockedWidth(true);
PdfPCell contractor = new PdfPCell(new Phrase("XXXXXXXXXXXXX"));
contractor.setColspan(5);
table.addCell(contractor);
PdfPCell workType = new PdfPCell(new Phrase("Refractory Works"));
workType.setColspan(5);
table.addCell(workType);
PdfPCell supervisor = new PdfPCell(new Phrase("XXXXXXXXXXXXXX"));
supervisor.setColspan(4);
table.addCell(supervisor);
PdfPCell paySlipHead = new PdfPCell(new Phrase("XXXXXXXXXXXXXXXX"));
paySlipHead.setColspan(10);
table.addCell(paySlipHead);
PdfPCell paySlipMonth = new PdfPCell(new Phrase("XXXXXXX"));
paySlipMonth.setColspan(2);
table.addCell(paySlipMonth);
PdfPCell blank = new PdfPCell(new Phrase(""));
blank.setColspan(9);
table.addCell(blank);
document.add(table);
행에 대해 걱정할 필요가 없습니다. iText는 PdfPRow
내부적 으로 인스턴스를 생성 합니다 ( 문서화 된대로 ).
결과는 다음과 같습니다. simple_table3.pdf
예외가 발생하지 않습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다