도움이 필요합니다. 지난 4 시간 동안 PDF 파일 총 페이지 수를 보냈습니다. 내 꼬리말에 "Page X/Y"와 같은 것을 넣고 싶습니다. 누군가이 코드로 무엇을 할 수 있는지 말해 줄 수 있습니까?PDF 파일의 총 페이지 수를 얻는 방법 - iTextSharp, C#
확인
public class pdfPage : PdfPageEventHelper
{
public override void OnEndPage(PdfWriter writer, Document doc)
{
iTextSharp.text.Rectangle page = doc.PageSize;
//PdfPTable EndTable = new PdfPTable(2);
PdfPTable EndTable = new PdfPTable(2);
EndTable.DefaultCell.Padding = 2f;
EndTable.HorizontalAlignment = Element.ALIGN_JUSTIFIED;
iTextSharp.text.Font smallfont2 = FontFactory.GetFont(FontFactory.HELVETICA, "CP1250", 10);
PdfPCell stopka1 = new PdfPCell(new Phrase("Left column - not important", smallfont2));
stopka1.BorderWidthLeft = 0;
stopka1.BorderWidthBottom = 0;
stopka1.BorderWidthRight = 0;
stopka1.HorizontalAlignment = Element.ALIGN_LEFT;
stopka1.VerticalAlignment = Element.ALIGN_MIDDLE;
PdfPCell stopka2 = new PdfPCell(new Phrase("Page " + doc.PageNumber + "/", smallfont2));
stopka2.BorderWidthLeft = 0;
stopka2.BorderWidthBottom = 0;
stopka2.BorderWidthRight = 0;
stopka2.HorizontalAlignment = Element.ALIGN_RIGHT;
stopka2.VerticalAlignment = Element.ALIGN_MIDDLE;
EndTable.AddCell(stopka1);
EndTable.AddCell(stopka2);
EndTable.TotalWidth = page.Width - doc.LeftMargin - doc.RightMargin;
EndTable.WriteSelectedRows(0, -1, doc.LeftMargin, EndTable.TotalHeight + doc.BottomMargin - 45, writer.DirectContent);
}
}
편집, 나는 그것을 밖으로 분류. 단순히 작업중인 PDF 파일을 닫은 다음 임시 파일로 복사했습니다. 그런 다음 "OnEndPage"메서드에서이 임시 문서의 페이지를 계산했습니다. 나중에이 임시 파일의 모든 내용을 복사 한 새 문서를 열어 pdfPage 클래스의 객체를 만들고 writer2.PageEvent에 연결했습니다. 이제 작동합니다.
당신은 우리에게 당신의 코드를주었습니다. 그러나 당신은 당신의 코드가 당신에게 어떤 의미로 실패했는지 (그렇게 좋지는 않다) 설명하지 않았다. 기존 코드가 얼마나 실패했는지 자세히 설명하십시오. –
지금 무엇을 해야할지 모르겠습니다. 나는이 "PDF 파일의 전체 페이지 수"를 얻고 여기에 넣는 방법을 모른다. - PdfPCell stopka2 = 새로운 PdfPCell (새로운 문구 ("Page"+ doc.PageNumber + "/", smallfont2)); –