iText Java - add header to an existing pdf -
I want to add a header to an existing PDF using iText.
I did not have any problems other than that sometimes my function creates a PDF with the right header and footer, but it is rotated with the current PDF page.
Private static zero print (Sldocument item, string header, string footer) {try string string ftpFilename = item.getId () + "_" + item.getDocumentname (); String newName = String.valueOf (item.getId ()) + ".pdf"; String path = (global. SHARED_FOLDER_DEVELOPER); String smbUser = "**" "+" ** "+": "+" ** "; NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication (smbUser); Smbifail sFile = new Smbifail (path + Fteepifailnam, Auth); InputStream = sFile.getInputStream () in; PDF Reader reader = new PDF reader (these); // output Create PDF document = new document (Pejasijh. a 4); SmbFile sFileOut = new SmbFile (path + new name, Auth); SmbFileOutputStream sfos = new SmbFileOutputStream (sFileOut); PDF author = PDF writer. Instens (document SFO); document.open (); PdfContentByte pdfContentByte = writer.getDirectContent () For; (Int i = 1; i & lt; = reader.getNumberOfPages (); i ++) {Peedifayatit Page = Lekkkaiojitapej (Reader, I); DocumentknewPage (); PdfContentBytekadd ( Page); // Header List Text (HeadPositionX, HeadPassion U, Header); // Write Footer Write Text (Footer, Footer, Footer); // Page Number String Page Number = "Page" + i + "Di" + reader.getNumberOfPages (); Writing Lessons (PayPalposition, PayPalposition, PayJender); } Document.close (); Reader.close (); } Hold (DocumentException e) {e.printStackTrace (); } Hold (IOException e) {e.printStackTrace (); }} I tried to resolve my problem
AffineTransform af = new AffineTransform (); Af.setToRotation (Math.toRadians (page.getRotation ())); PdfContentByte.addTemplate (Page, AF); Simple insthead
pdfContentByte.add (page); But with this change, the imported page is completely unavailable from my new PDF (probably because I used to rotate the page using the wrong anchor point).
How can I do this according to MKL I used PDF stamper:
> Private static void Print (Sldocument item, string header, string footer) {try string {} ftpFilename = item.getId () + "_" + item.getDocumentname (); String newName = String.valueOf (item.getId ()) + ".pdf"; String path = (global. SHARED_FOLDER_DEVELOPER); String smbUser = "**" "+" ** "+": "+" ** "; NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication (smbUser); Smbifail sFile = new Smbifail (path + Fteepifailnam, Auth); InputStream = sFile.getInputStream (a); PDF Reader reader = new PDF reader (these); // output PDF Create SmbFile sFileOut = new Smbifail (path + new name, Auth); SmbFileOutputStream sfos = new SmbFileOutputStream (sFileOut); Peedifstampr Stamr = new Peedifstamr (Reader , SFOs); // loop on the page and add a header to each page for int n = reader.getNumberOfPages (); Front I = 1; i & lt; = n; i ++) Add {// header Peedifpitibl table = new Peedifpitibl (1); table.setTotalWidth (PDF_PAGE_SIZE.getWidth () - (headerPositionX * 2)); table.setLockedWidth (right); table.getDefaultCell () setFixedHeight (20). table.getDefaultCell () setBorder (Rectangle.NO_BORDER). table.addCell (header);. Table.getDefaultCell () setHorizontalAlignment (Element.ALIGN_RIGHT); table.addCell ( ""); Table. Written line selected (0, -1, HeadPointX, Header Position, stamper.getOverContent (i)); // Add Footer PdfPTable tableFooter = New PDFPTable (2); TableFooter.setTotalWidth (PDF_PAGE_SIZE.getWidth () - (footerPositionX * 2)); TableFooter.setLockedWidth (true); TableFooter.getDefaultCell () setFixedHeight (20). TableFooter.getDefaultCell () setBorder (Rectangle.NO_BORDER). TableFooter.addCell (footer); . TableFooter.getDefaultCell () setHorizontalAlignment (Element.ALIGN_RIGHT); TableFooter.addCell (string format ("% d of page% d", i, n)); Tablefooter.Located Lite Selected (0, -1, Footer Line, Footer Promotion * 4, Stampar.GetOver Content (I)); } // Stop Stampers Stampers Close (); Reader.close (); } Hold (DocumentException e) {e.printStackTrace (); } Hold (IOException e) {e.printStackTrace (); }}
Comments
Post a Comment