List of usage examples for com.itextpdf.text Document getPageSize
public Rectangle getPageSize()
From source file:com.vectorprint.report.itext.debug.DebugHelper.java
License:Open Source License
/** * This method will append to the pdf a legend explaining the visual feedback in the pdf, an overview of the styles * used and an overview of the properties used. * * @throws DocumentException//from w w w . j a v a2 s .c o m */ public static void appendDebugInfo(PdfWriter writer, Document document, EnhancedMap settings, StylerFactory stylerFactory) throws DocumentException, VectorPrintException { PdfContentByte canvas = writer.getDirectContent(); canvas.setFontAndSize(FontFactory.getFont(FontFactory.COURIER).getBaseFont(), 8); canvas.setColorFill( itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); canvas.setColorStroke( itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); Font f = FontFactory.getFont(FontFactory.COURIER, 8); f.setColor(itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); float top = document.getPageSize().getTop(); document.add(new Phrase(new Chunk("table: ", f).setLocalDestination(DEBUGPAGE))); document.add(Chunk.NEWLINE); document.add(new Phrase("cell: ", f)); document.add(Chunk.NEWLINE); document.add(new Phrase("image: ", f)); document.add(Chunk.NEWLINE); document.add(new Phrase("text: ", f)); document.add(Chunk.NEWLINE); document.add(new Phrase("background color is shown in a small rectangle", f)); document.add(Chunk.NEWLINE); canvas.setLineWidth(2); canvas.setLineDash(new float[] { 0.3f, 5 }, 0); float left = document.leftMargin(); canvas.rectangle(left + 80, top - 25, left + 80, 8); canvas.closePathStroke(); canvas.setLineWidth(0.3f); canvas.setLineDash(new float[] { 2, 2 }, 0); canvas.rectangle(left + 80, top - 37, left + 80, 8); canvas.closePathStroke(); canvas.setLineDash(new float[] { 1, 0 }, 0); canvas.rectangle(left + 80, top - 50, left + 80, 8); canvas.closePathStroke(); canvas.setLineDash(new float[] { 0.3f, 5 }, 0); canvas.rectangle(left + 80, top - 63, left + 80, 8); canvas.closePathStroke(); document.add(Chunk.NEWLINE); document.add(new Phrase("fonts available: " + FontFactory.getRegisteredFonts(), f)); document.add(Chunk.NEWLINE); if (settings.getBooleanProperty(false, DEBUG)) { document.add(new Phrase("OVERVIEW OF STYLES FOR THIS REPORT", f)); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); } Font b = new Font(f); b.setStyle("bold"); Set<Map.Entry<String, String>> entrySet = stylerFactory.getStylerSetup().entrySet(); for (Map.Entry<String, String> styleInfo : entrySet) { String key = styleInfo.getKey(); document.add(new Chunk(key, b).setLocalDestination(key)); document.add(new Chunk(": " + styleInfo.getValue(), f)); document.add(Chunk.NEWLINE); document.add(new Phrase(" styling configured by " + key + ": ", f)); for (BaseStyler st : (Collection<BaseStyler>) stylerFactory.getBaseStylersFromCache((key))) { document.add(Chunk.NEWLINE); document.add(new Chunk(" ", f)); document.add(new Chunk(st.getClass().getSimpleName(), DebugHelper.debugFontLink(canvas, settings)) .setLocalGoto(st.getClass().getSimpleName())); document.add(new Chunk(":", f)); document.add(Chunk.NEWLINE); document.add(new Phrase(" non default parameters for " + st.getClass().getSimpleName() + ": " + getParamInfo(st), f)); document.add(Chunk.NEWLINE); if (!st.getConditions().isEmpty()) { document.add(new Phrase(" conditions for this styler: ", f)); } for (StylingCondition sc : (Collection<StylingCondition>) st.getConditions()) { document.add(Chunk.NEWLINE); document.add(new Chunk(" ", f)); document.add( new Chunk(sc.getClass().getSimpleName(), DebugHelper.debugFontLink(canvas, settings)) .setLocalGoto(sc.getClass().getSimpleName())); document.add(Chunk.NEWLINE); document.add(new Phrase(" non default parameters for " + sc.getClass().getSimpleName() + ": " + getParamInfo(sc), f)); } } document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); } document.newPage(); document.add(new Phrase("Properties used for the report", f)); document.add(Chunk.NEWLINE); ByteArrayOutputStream bo = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(bo); settings.listProperties(ps); ps.close(); document.add(new Paragraph(bo.toString(), f)); document.newPage(); try { bo = new ByteArrayOutputStream(); ps = new PrintStream(bo); Help.printHelpHeader(ps); ps.close(); document.add(new Paragraph(bo.toString(), f)); Help.printStylerHelp(document, f); Help.printConditionrHelp(document, f); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) { log.log(Level.SEVERE, null, ex); } }
From source file:com.vectorprint.report.itext.EventHelper.java
License:Open Source License
/** * prepares template for printing header and footer * * @param writer/*w w w. j ava2s . c om*/ * @param document */ @Override public final void onOpenDocument(PdfWriter writer, Document document) { super.onOpenDocument(writer, document); template = writer.getDirectContent().createTemplate(document.getPageSize().getWidth(), document.getPageSize().getHeight()); if (!getSettings().containsKey(PAGEFOOTERSTYLEKEY)) { getSettings().put(PAGEFOOTERSTYLEKEY, PAGEFOOTERSTYLE); } if (!getSettings().containsKey(PAGEFOOTERTABLEKEY)) { float tot = ItextHelper .ptsToMm(document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin()); getSettings().put(PAGEFOOTERTABLEKEY, new StringBuilder("Table(columns=3,widths=") .append(Math.round(tot * getSettings().getFloatProperty(0.85f, "footerleftwidthpercentage"))) .append('|') .append(Math.round(tot * getSettings().getFloatProperty(0.14f, "footermiddlewidthpercentage"))) .append('|') .append(Math.round(tot * getSettings().getFloatProperty(0.01f, "footerrightwidthpercentage"))) .append(')').toString()); } }
From source file:com.vectorprint.report.itext.EventHelper.java
License:Open Source License
/** * prints debug info when property debug is true, calls renderHeader and renderFooter and * {@link Advanced#draw(com.itextpdf.text.Rectangle, java.lang.String) } with {@link Document#getPageSize() } * and null for {@link DefaultStylerFactory#PAGESTYLERS}. * * @param writer/* w w w . j a va 2 s . c om*/ * @param document */ @Override public final void onEndPage(PdfWriter writer, Document document) { super.onEndPage(writer, document); sanitize(writer); try { if (failuresHereAfter || debugHereAfter) { PdfContentByte bg = writer.getDirectContentUnder(); Rectangle rect = writer.getPageSize(); rect.setBackgroundColor(itextHelper .fromColor(getSettings().getColorProperty(new Color(240, 240, 240), "legendbackground"))); bg.rectangle(rect); bg.closePathFillStroke(); } else { for (Advanced a : doForAllPages) { try { if (a.shouldDraw(null)) { a.draw(document.getPageSize(), null); } } catch (VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } } } if (!debugHereAfter && getSettings().getBooleanProperty(false, DEBUG)) { PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = new Rectangle(document.leftMargin(), document.bottomMargin(), document.right() - document.rightMargin(), document.top() - document.topMargin()); DebugHelper.debugRect(canvas, rect, new float[] { 10, 2 }, 0.3f, getSettings(), stylerFactory.getLayerManager()); } renderHeader(writer, document); maxTagForGenericTagOnPage = ((DefaultElementProducer) elementProducer).getAdvancedTag(); if (getSettings().getBooleanProperty(Boolean.FALSE, ReportConstants.PRINTFOOTER)) { renderFooter(writer, document); } else { log.warning("not printing footer, if you want page footers set " + ReportConstants.PRINTFOOTER + " to true"); } maxTagForGenericTagOnPage = Integer.MAX_VALUE; } catch (VectorPrintException | DocumentException | InstantiationException | IllegalAccessException e) { throw new VectorPrintRuntimeException("failed to create the report header or footer: ", e); } }
From source file:com.vectorprint.report.itext.EventHelper.java
License:Open Source License
/** * prints a footer table with a line at the top, a date and page numbering, second cell will be right aligned * * @see #PAGEFOOTERTABLEKEY/*ww w . j ava2 s.com*/ * @see #PAGEFOOTERSTYLEKEY * * @param writer * @param document * @throws DocumentException * @throws VectorPrintException */ protected void renderFooter(PdfWriter writer, Document document) throws DocumentException, VectorPrintException, InstantiationException, IllegalAccessException { if (!debugHereAfter && !failuresHereAfter) { PdfPTable footerTable = elementProducer.createElement(null, PdfPTable.class, getStylers(PAGEFOOTERTABLEKEY)); footerTable.addCell(createFooterCell(ValueHelper.createDate(new Date()))); String pageText = writer.getPageNumber() + getSettings().getProperty(" of ", UPTO); PdfPCell c = createFooterCell(pageText); c.setHorizontalAlignment(Element.ALIGN_RIGHT); footerTable.addCell(c); footerTable.addCell(createFooterCell(new Chunk())); footerTable.writeSelectedRows(0, -1, document.getPageSize().getLeft() + document.leftMargin(), document.getPageSize().getBottom(document.bottomMargin()), writer.getDirectContentUnder()); footerBottom = document.bottom() - footerTable.getTotalHeight(); } }
From source file:com.vectorprint.report.itext.TocOutputStream.java
License:Open Source License
private void printToc(Document d, PdfWriter w, VectorPrintDocument vpd) throws VectorPrintException, InstantiationException, IllegalAccessException, DocumentException { DocumentStyler ds = outer.getStylerFactory().getDocumentStyler(); if (ds.getValue(DocumentSettings.TOCAPPEND, Boolean.class)) { d.add(Chunk.NEXTPAGE);// www . j a va2s . com } if (outer.isWasDebug()) { outer.getSettings().put(ReportConstants.DEBUG, Boolean.TRUE.toString()); PdfContentByte canvas = w.getDirectContent(); outer.startLayerInGroup(ReportConstants.DEBUG, canvas); BaseFont bf = DebugHelper.debugFont(canvas, outer.getSettings()); canvas.showTextAligned(Element.ALIGN_RIGHT, "FOR DEBUG INFO IN THE DOCUMENT TURN OFF TOC (-DocumentSettings.toc=false)", d.right(), d.getPageSize().getHeight() - ItextHelper.getTextHeight("F", bf, 8), 0); canvas.endLayer(); } ElementProducer ep = outer.getElementProducer(); StylerFactory sf = outer.getStylerFactory(); PdfPTable tocTable = ep.createElement(null, PdfPTable.class, sf.getStylers(DocumentSettings.TOCTABLEKEY)); for (Map.Entry<Integer, List<Section>> e : vpd.getToc().entrySet()) { String link = null; for (Section s : e.getValue()) { if (ds.isParameterSet(DocumentSettings.TOCMAXDEPTH) && ds.getValue(DocumentSettings.TOCMAXDEPTH, Integer.class) < s.getDepth()) { continue; } if (link == null) { link = s.getTitle().getContent(); } Chunk c = ep.createElement(s.getTitle().getContent(), Chunk.class, sf.getStylers(DocumentSettings.TOCTITLESTYLEKEY)); if (ds.getValue(DocumentSettings.TOCDOTS, Boolean.class)) { float tw = ItextHelper.getTextWidth(c); float cw = tocTable.getAbsoluteWidths()[0]; float dw = ItextHelper.getTextWidth( ep.createElement(".", Chunk.class, sf.getStylers(DocumentSettings.TOCTITLESTYLEKEY))) * 1.5f; int numDots = (int) ((cw > tw) ? (cw - tw) / dw : 0); char[] dots = new char[numDots]; Arrays.fill(dots, '.'); c = ep.createElement(s.getTitle().getContent() + " " + String.valueOf(dots), Chunk.class, sf.getStylers(DocumentSettings.TOCTITLESTYLEKEY)); } c.setLocalGoto(link); tocTable.addCell( ep.createElement(c, PdfPCell.class, sf.getStylers(DocumentSettings.TOCTITLESTYLEKEY))); c = ep.createElement(e.getKey(), Chunk.class, sf.getStylers(DocumentSettings.TOCNRSTYLEKEY)); c.setLocalGoto(link); tocTable.addCell( ep.createElement(c, PdfPCell.class, sf.getStylers(DocumentSettings.TOCNRSTYLEKEY))); } } d.add(tocTable); }
From source file:com.vimbox.hr.LicensePDFGenerator.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . ja v a 2s . c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); String fileName = request.getParameter("license_name"); String ext = fileName.substring(fileName.lastIndexOf(".") + 1); String path = System.getProperty("user.dir") + "/documents/licenses/" + fileName; path = path.replaceAll("%20", " "); if (ext.equalsIgnoreCase("pdf")) { FileInputStream baos = new FileInputStream(path); OutputStream os = response.getOutputStream(); byte buffer[] = new byte[8192]; int bytesRead; while ((bytesRead = baos.read(buffer)) != -1) { os.write(buffer, 0, bytesRead); } os.flush(); os.close(); } else { try { // Document Settings // Document document = new Document(); PdfWriter.getInstance(document, response.getOutputStream()); document.open(); // Loading MC // PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); // the cell object PdfPCell cell; Image img = Image.getInstance(path); int indentation = 0; float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin() - indentation) / img.getWidth()) * 100; img.scalePercent(scaler); //img.scaleAbsolute(80f, 80f); cell = new PdfPCell(img); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); document.add(table); //-----------------------------------// document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } } }
From source file:com.wabacusdemo.PdfInterceptor_dataexportpdfpage1_vp7.java
License:Open Source License
/** * ?PDF??PDF?/*w ww . ja v a2s.c o m*/ * ??? */ public void afterDisplayPdfPageWithoutTemplate(Document document, AbsReportType reportTypeObj) { super.afterDisplayPdfPageWithoutTemplate(document, reportTypeObj); ReportRequest rrequest = reportTypeObj.getReportRequest(); String serverName = rrequest.getRequest().getServerName(); String serverPort = String.valueOf(rrequest.getRequest().getServerPort()); String imgurl = "http://" + serverName + ":" + serverPort + Config.webroot + "wabacusdemo/pdftemplate/logo.gif";//?URL try { Image img = Image.getInstance(imgurl); float width = document.getPageSize().getWidth(); float height = document.getPageSize().getHeight(); //width = width - img.getWidth(); img.setAbsolutePosition(width / 2, height / 2 + 300f); img.setAlignment(Image.ALIGN_CENTER); document.add(img); } catch (Exception e) { e.printStackTrace(); } }
From source file:Controller.app.ConsultaController.java
private File createPDF(TblServicioFactura factura) throws IOException { String data = factura.getTesPagoResponse(); JSONObject obj = new JSONObject(data); JSONArray content = obj.getJSONArray("lineaFactura"); String temp = ""; File _file = null;/* w ww .j a va2 s. co m*/ Document doc = null; OutputStream file = null; int page = 0; try { _file = File.createTempFile("temp_file", ".pdf"); TblServicioServicio servicio = servicios.search(factura.getTesCodigoSintesisBi().toString()); file = new FileOutputStream(_file); doc = new Document(PageSize.LETTER); doc.setMargins(servicio.getMarginLeft().floatValue(), servicio.getMarginRight().floatValue(), servicio.getMarginTop().floatValue(), servicio.getMarginBottom().floatValue()); PdfWriter.getInstance(doc, file); doc.open(); // ClassLoader classloader = Thread.currentThread().getContextClassLoader(); ClassLoader classloader = getClass().getClassLoader(); URL url = classloader.getResource("cour.ttf"); BaseFont base = null; if (url == null) { base = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } else { String path = url.getPath(); if ("/".equals(path.substring(0, 1))) { path = path.substring(1); } Logger.getLogger(ConsultaController.class.getName()).log(Level.INFO, path); base = BaseFont.createFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } Font f = new Font(base, servicio.getFontSize(), Font.NORMAL, BaseColor.BLACK); String qr = ""; float line = 0; for (Object item : content) { Paragraph paragraph = new Paragraph(item.toString(), f); if (servicio.getTesDetalleVc().trim().equals("PAGO ENTEL")) { if (item.toString().contains("P X#X&$#&K##")) { paragraph = new Paragraph(" ", f); doc.add(paragraph); doc.add(paragraph); paragraph = new Paragraph(item.toString(), f); } } if (item.toString().contains("<b>")) { Font bold = new Font(base, 7.0f, Font.BOLD, BaseColor.BLACK); paragraph = new Paragraph(item.toString().replace("<b>", ""), bold); } if (item.toString().contains("<QR>") || item.toString().contains("<QR_ENT_G>")) { qr = item.toString().replaceAll("<QR>", ""); qr = item.toString().replaceAll("<QR_ENT_G>", ""); Image image = QR.create(qr); image.scaleAbsolute(servicio.getQrScale().floatValue(), servicio.getQrScale().floatValue()); if (servicio.getTesDetalleVc().trim().equals("PAGO ENTEL") || servicio.getTesDetalleVc().trim().equals("PAGO TELECEL") || servicio.getTesDetalleVc().trim().equals("PAGO NUEVATEL") || servicio.getTesDetalleVc().trim().equals("PAGO TIGOSTAR (MULTIVISION)")) { float y = (doc.getPageSize().getHeight() - (paragraph.getLeading() * (line + 1))); float x = 0; if (servicio.getTesDetalleVc().trim().equals("PAGO ENTEL")) { image.setAlignment(Image.ALIGN_RIGHT); x = doc.getPageSize().getWidth() - (110 - servicio.getMarginLeft().floatValue()); } if (servicio.getTesDetalleVc().trim().equals("PAGO TELECEL")) { image.setAlignment(Image.ALIGN_LEFT); x = 30; y -= (servicio.getQrScale().floatValue() - (paragraph.getLeading() * 2)); } if (servicio.getTesDetalleVc().trim().equals("PAGO NUEVATEL")) { image.setAlignment(Image.ALIGN_LEFT); x = doc.getPageSize().getWidth() - (120 - servicio.getMarginLeft().floatValue()); y -= (servicio.getQrScale().floatValue() - (paragraph.getLeading())); } if (servicio.getTesDetalleVc().trim().equals("PAGO TIGOSTAR (MULTIVISION)")) { image.setAlignment(Image.ALIGN_LEFT); x = doc.getPageSize().getWidth() - (120 - servicio.getMarginLeft().floatValue()); y -= (servicio.getQrScale().floatValue() - (paragraph.getLeading())); } image.setAbsolutePosition(x, y); } doc.add(image); } if (servicio.getDelimitador().equals(item.toString().trim())) { line = 0; page++; doc.newPage(); } else { line += 1f; if (!(item.toString().contains("<QR>") || item.toString().contains("<QR_ENT_G>"))) { doc.add(paragraph); } } temp += item.toString(); } } catch (FileNotFoundException ex) { Logger.getLogger(ConsultaController.class.getName()).log(Level.INFO, null, ex); } catch (DocumentException | IOException ex) { Logger.getLogger(ConsultaController.class.getName()).log(Level.INFO, null, ex); } doc.close(); file.close(); return _file; }
From source file:de.extra.xtt.util.pdf.PdfCreatorImpl.java
License:Apache License
/** * Erzeugt das Inhaltsverzeichnis aus den bereits vorhandenen Elementen in * der Liste <code>listEntries</code>. * // w w w. j a va2 s. c o m * @param docPdf * Zieldokument, falls Inhaltsverzeichnis nicht temporr erzeugt * wird * @param temp * Gibt an, ob das Inhaltsverzeichnis temporr in einer neuen * Datei/Dokument erzeugt werden soll * @return Anzahl der Seiten * @throws DocumentException * @throws IOException */ private int erzeugeInhaltsverzeichnis(Document docPdf, boolean temp) throws DocumentException, IOException { int anzPages = 0; Document docInhalt = docPdf; String filePathTempInhaltString = ""; if (temp) { // temp. Dateinamen bestimmen File fileDokuFile = new File(dateiname); filePathTempInhaltString = fileDokuFile.getParent() + "/tmp_inhalt.pdf"; // Neues Dokument erzeugen docInhalt = initPdfWriterAndDocument(filePathTempInhaltString, false); } // berschrift Chapter currChapter = new Chapter(getParagraphChapter("Inhaltsverzeichnis"), 0); // 0, damit keine Nummerierung currChapter.setNumberDepth(0); docInhalt.add(currChapter); // eine Zeile Abstand docInhalt.add(getEmptyLineTextHalf()); for (ContPdfEntry currEntry : listEntries) { // Eintrag erzeugen inkl. Abstand String strEintrag = currEntry.getBezeichnung() + " "; Chunk chunkBezeichnung; Chunk chunkSeitenzahlChunk; if (currEntry.getParentEntry() == null) { // 1. Ebene => fett, Abstand davor einfgen docInhalt.add(getEmptyLineTextHalf()); chunkBezeichnung = getChunkTextBold(strEintrag); chunkSeitenzahlChunk = getChunkTextBold("" + currEntry.getPageNumber()); } else { // 2. Ebene chunkBezeichnung = getChunkText(strEintrag); chunkSeitenzahlChunk = getChunkText("" + currEntry.getPageNumber()); } // Referenz setzen chunkBezeichnung.setLocalGoto(currEntry.getDestination()); chunkSeitenzahlChunk.setLocalGoto(currEntry.getDestination()); // Abstandzeichen generieren, Breite auffllen float widthAbstand = docInhalt.getPageSize().getWidth() * 0.81f; ; while (chunkBezeichnung.getWidthPoint() <= widthAbstand) { chunkBezeichnung.append("."); } // Tabelle erzeugen und formatieren PdfPTable currTable = new PdfPTable(2); currTable.setWidthPercentage(100f); currTable.setWidths(new int[] { 96, 4 }); // Inhalte einfgen // Zelle Bezeichnung PdfPCell currCellBezeichnung = new PdfPCell(new Phrase(chunkBezeichnung)); currCellBezeichnung.setBorder(0); currCellBezeichnung.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL); // Zelle Seitennummer PdfPCell currCellPageNumberCell = new PdfPCell(new Phrase(chunkSeitenzahlChunk)); currCellPageNumberCell.setBorder(0); currCellPageNumberCell.setHorizontalAlignment(Element.ALIGN_RIGHT); // Zellen zur Tabelle hinzufgen currTable.addCell(currCellBezeichnung); currTable.addCell(currCellPageNumberCell); docInhalt.add(currTable); } if (temp) { // Dokument schlieen docInhalt.close(); // Anzahl der Seitenzahlen bestimmen PdfReader reader = new PdfReader(filePathTempInhaltString); anzPages = reader.getNumberOfPages(); reader.close(); // temp. Datei lschen File currFileInhaltFile = new File(filePathTempInhaltString); currFileInhaltFile.delete(); } return anzPages; }
From source file:de.jost_net.JVerein.io.HeaderFooter.java
License:Open Source License
/** * Adds the header and the footer./*from w w w . j a va 2 s .c o m*/ * */ @Override public void onEndPage(PdfWriter writer, Document document) { Rectangle rect = document.getPageSize(); switch (writer.getPageNumber() % 2) { case 0: // ColumnText.showTextAligned(writer.getDirectContent(), // Element.ALIGN_RIGHT, header[0], rect.getRight(), rect.getTop(), 0); break; case 1: // ColumnText.showTextAligned(writer.getDirectContent(), // Element.ALIGN_LEFT, // header[1], rect.getLeft(), rect.getTop(), 0); break; } float left = rect.getLeft() + document.leftMargin(); float right = rect.getRight() - document.rightMargin(); float bottom = rect.getBottom() + document.bottomMargin(); PdfContentByte pc = writer.getDirectContent(); pc.setColorStroke(BaseColor.BLACK); pc.setLineWidth(0.5f); pc.moveTo(left, bottom - 5); pc.lineTo(right, bottom - 5); pc.stroke(); pc.moveTo(left, bottom - 25); pc.lineTo(right, bottom - 25); pc.stroke(); ColumnText.showTextAligned(pc, Element.ALIGN_CENTER, new Phrase(footer + " " + pagenumber, Reporter.getFreeSans(7)), (left + right) / 2, bottom - 18, 0); }