텍스트 보고서를 생성하는 함수가 있습니다. 데이터베이스에서 문서 텍스트 목록을 가져와 PDF 보고서를 만듭니다. 해당 문서의 반복에 대한 헤더 정보를 한 페이지 이상을 실행할 수 있습니다텍스트가 Internet Explorer 용 iText5를 사용하여 표 셀에 배치되지 않습니다.
logo(top left).........some static text about company (top right) [header information that is...................................... .........................different for each document in the list] [.....................document text.............................] date(bottom left) page count(bottom right)
문서의 텍스트를 다음과 경우에서와 같이 PDF 보고서 형식이어야합니다. 그리고 문서 텍스트가 두 번째 페이지를 실행하고 중간 페이지에서 끝나면 새 페이지에서 다음 문서를 시작합니다. 문서 텍스트가 페이지의 여백이 부족 매우 긴 라인을 가지고 있으며, 당신이 그것을 볼 수 없습니다 때
public static void printDocument(List<PdfData> lst, ref MemoryStream memoryStream)
{
iTextSharp.text.Font baseFontBig = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK);
iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.LETTER, 40, 25, 30, 30);
PDFEvents e = new PDFEvents();
PdfWriter pw = PdfWriter.GetInstance(document, memoryStream);
pw.PageEvent = e;
document.Open();
for (int i = 0; i < lst.Count; i++)
{
PdfPTable mainTable = new PdfPTable(2);
PdfPTable outerTable = new PdfPTable(4);
PdfPTable contentTable = new PdfPTable(1);
mainTable.KeepTogether = true;
outerTable.WidthPercentage = 50;
outerTable.KeepTogether = false;
outerTable.TotalWidth = 550f;
float[] sglTblHdWidths = new float[4];
sglTblHdWidths[0] = 5f;
sglTblHdWidths[1] = 15f;
sglTblHdWidths[2] = 5f;
sglTblHdWidths[3] = 5f;
outerTable.SetWidths(sglTblHdWidths);
outerTable.LockedWidth = true;
contentTable.LockedWidth = true;
outerTable.KeepTogether = true;
contentTable.WidthPercentage = 90;
contentTable.KeepTogether = false;
contentTable.TotalWidth = 800f;
contentTable.SpacingBefore = 30f;
string documentIdentifier = lst[i].patient;
string documentStatus =lst[i].documentStatus;
StringBuilder sb = new StringBuilder();
sb.Append(lst[i].documentText);
iTextSharp.text.Paragraph documentStatusP = new iTextSharp.text.Paragraph(documentStatus, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 12, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK));
iTextSharp.text.Paragraph patient = new iTextSharp.text.Paragraph(documentIdentifier, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 12, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK));
iTextSharp.text.Paragraph content = new iTextSharp.text.Paragraph(sb.ToString(), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 10));
iTextSharp.text.Paragraph empty = new iTextSharp.text.Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 12));
#region Content
PdfPCell contentCell = new PdfPCell(content);
contentCell.Border =1;
contentCell.VerticalAlignment = Element.ALIGN_TOP;
contentCell.HorizontalAlignment = Element.ALIGN_LEFT;
contentTable.AddCell(contentCell);
#endregion
PdfPCell firstHeader = new PdfPCell(empty);
firstHeader.Border = 0;
firstHeader.FixedHeight = 17f;
outerTable.AddCell(firstHeader);
PdfPCell secondHeader = new PdfPCell(patient);
secondHeader.Border = 0;
secondHeader.FixedHeight = 17f;
secondHeader.VerticalAlignment = 2;
outerTable.AddCell(secondHeader);
PdfPCell thirdHeader = new PdfPCell(documentStatusP);
thirdHeader.Border = 0;
thirdHeader.FixedHeight = 17f;
thirdHeader.HorizontalAlignment = 1;
thirdHeader.VerticalAlignment = 2;
outerTable.AddCell(thirdHeader);
PdfPCell forthHeader = new PdfPCell(empty);
forthHeader.Border = 0;
forthHeader.FixedHeight = 17f;
outerTable.AddCell(forthHeader);
PdfPCell outerTblCell = new PdfPCell(outerTable);
outerTblCell.Border = 0;
PdfPCell contentTblCell = new PdfPCell(contentTable);
contentTblCell.Border = 0;
mainTable.AddCell(outerTblCell);
mainTable.AddCell(contentTblCell);
document.Add(mainTable);
if (i != lst.Count - 1)
document.NewPage();
}
document.Close();
}
이 콘텐츠 테이블에있는 것을 제외하고 보고서 및 필요한 값을 모두 표시 : 여기 내 시도이다. 이것을 더 잘 수행 할 수있는 방법이 있습니까? 감사!
이것은 더 많은 리팩토링 제안입니다. 당신이 제안한 것을했는데, 메인 테이블에 외부 테이블과 컨텐츠 테이블을 추가하면 두 셀이 공간을 병렬로 유지합니다. 이 두 셀을 겹치게하는 설정이있어서 첫 번째 필드가 맨 위와 맨 아래에있을 수 있습니까? – user2165673
나는 정확히 다음과 같은 것은 아니지만, 테이블 셀 안의 콘텐츠가 나란히 놓여 있다는 것을 의미합니까? –
mainTable.AddCell (outerTblCell); mainTable.AddCell (contentTblCell); 이 두 테이블은 mainTable에 나란히 표시됩니다. – user2165673