![]() ![]() PdfReader reader = new PdfReader(pdfAsBytes) īyteArrayOutputStream outputStream = new ByteArrayOutputStream() ĭataOutputStream output = new DataOutputStream(outputStream) Int pageCount = pdfWriter.getPageNumber()-1 īyte pdfAsBytes = pdfOutputStream.toByteArray() CREATE PDF HERE - ADD CONTENT TO DOCUMENT PdfWriter pdfWriter = PdfWriter.getInstance(document, pdfOutputStream) Here is an elaborate example based on the example of Milhous: Font smallFont = FontFactory.getFont("Arial", 9, Font.NORMAL) īyteArrayOutputStream pdfOutputStream = new ByteArrayOutputStream() ĭocument document = new Document(PageSize.A4, 70, 70, 40, 40) The ideal class to do this with is PdfStamper, which purpose is to add additional elements to an existing pdf/existing pdf pages. Then after that just set the value of your pdfwriter PageEvent like this : Dim PageEventHandler = New EnteteEtPiedDePage()Īs the other answers indicate, you will first need to create the pdf, then look how many pages the pdf you created contains and then add the footer to each page. Template.ShowText("" & Convert.ToString((writer.PageNumber - 1))) Public Overrides Sub OnCloseDocument(writer As PdfWriter, document As Document) Public Overrides Sub OnEndPage(writer As PdfWriter, document As Document)ĭim text As = "Page " & pageN & " de "ĭim len As Single = bf.GetWidthPoint(text, 8)Ĭb.SetTextMatrix(pageSize.GetLeft(40), pageSize.GetBottom(30))Ĭb.AddTemplate(template, pageSize.GetLeft(40) + len, pageSize.GetBottom(30))Ĭb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Imprimé le : " & PrintTime.ToShortDateString() & " à " & PrintTime.ToShortTimeString, pageSize.GetRight(40), pageSize.GetBottom(30), 0) Public Overrides Sub OnStartPage(writer As PdfWriter, document As Document)ĭim pageSize As Rectangle = document.PageSize Public Overrides Sub OnOpenDocument(writer As PdfWriter, document As Document)īf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED) Private PrintTime As DateTime = DateTime.Now ' this is the BaseFont we are going to use for the header / footer ' we will put the final number of pages in a template ' This is the contentbyte object of the writer Then override theses two functions like this : Imports You can create a class that inherits from PdfPageEventHelper
0 Comments
Leave a Reply. |