List of usage examples for com.lowagie.text Document right
public float right()
From source file:org.sonar.report.pdf.Events.java
License:Open Source License
private void printPageNumber(PdfWriter writer, Document document) { PdfContentByte cb = writer.getDirectContent(); cb.saveState();//from w w w . j a va2 s .c o m float textBase = document.bottom() - 20; try { cb.setFontAndSize(BaseFont.createFont("Helvetica", BaseFont.WINANSI, false), 12); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } cb.beginText(); cb.setTextMatrix(document.right() - 10, textBase); cb.showText(String.valueOf(writer.getPageNumber())); cb.endText(); cb.saveState(); }
From source file:org.sonarqube.report.extendedpdf.ExtendedEvents.java
License:Open Source License
private void printPageNumber(PdfWriter writer, Document document) { PdfContentByte cb = writer.getDirectContent(); cb.saveState();/*from w w w. ja v a2 s .c om*/ float textBase = document.bottom() - 45; try { cb.setFontAndSize(BaseFont.createFont("Helvetica", BaseFont.WINANSI, false), 12); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } cb.beginText(); cb.setTextMatrix(document.right() - 10, textBase); cb.showText(String.valueOf(writer.getPageNumber())); cb.endText(); cb.saveState(); }
From source file:org.unitime.timetable.util.PdfEventHandler.java
License:Open Source License
/** * Print footer string on each page//from ww w . j a va2 s . c o m * @param writer * @param document */ public void onEndPage(PdfWriter writer, Document document) { if (getDateTime() == null) { setDateTime(new Date()); } PdfContentByte cb = writer.getDirectContent(); cb.beginText(); cb.setFontAndSize(getBaseFont(), getFontSize()); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, getDateFormat().format(getDateTime()), document.left(), 20, 0); cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, String.valueOf(document.getPageNumber()), document.right(), 20, 0); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, MESSAGES.pdfCopyright(Constants.getVersion()), (document.left() + document.right()) / 2, 20, 0); cb.endText(); return; }
From source file:questions.objects.DifferentLeadings.java
public static void main(String[] args) { Document document = new Document(PageSize.A7); try {//from www .j a va2 s. c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); Chunk space = new Chunk(' '); String text = "Quick brown fox jumps over the lazy dog."; Phrase phrase1 = new Phrase(text, new Font(Font.HELVETICA, 12)); Phrase phrase2 = new Phrase(new Chunk(text, new Font(Font.TIMES_ROMAN, 24))); Phrase phrase3 = new Phrase(text, new Font(Font.COURIER, 8)); Phrase phrase4 = new Phrase(text, new Font(Font.HELVETICA, 4)); Paragraph paragraph = new Paragraph(); paragraph.add(phrase1); paragraph.add(space); paragraph.add(phrase2); paragraph.add(space); paragraph.add(phrase3); paragraph.add(space); paragraph.add(phrase4); paragraph.setMultipliedLeading(1.5f); paragraph.setAlignment(Element.ALIGN_JUSTIFIED); ColumnText column = new ColumnText(writer.getDirectContent()); column.setSimpleColumn(document.left(), document.bottom(), document.right(), document.top()); column.addElement(paragraph); column.go(); document.newPage(); document.add(paragraph); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:questions.separators.DottedGlue.java
public static void main(String[] args) { Document document = new Document(); try {/*from w w w. j a v a 2 s . co m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); PdfContentByte canvas = writer.getDirectContent(); canvas.moveTo(document.left(), document.top()); canvas.lineTo(document.left(), 550); canvas.moveTo(document.right(), document.top()); canvas.lineTo(document.right(), 550); canvas.stroke(); Chunk separator = new Chunk(new DottedLineSeparator()); // two parts Paragraph p1 = new Paragraph(); p1.add(new Chunk("Chapter 1")); p1.add(separator); p1.add(new Chunk("p 10")); // 3 parts Paragraph p2 = new Paragraph(); p2.add(new Chunk("Chapter 2")); p2.add(separator); p2.add(new Chunk("x")); p2.add(separator); p2.add(new Chunk("y")); // line ends with separator Paragraph p3 = new Paragraph(); p3.add(new Chunk("Chapter 3")); p3.add(separator); // line starts with a separator Paragraph p4 = new Paragraph(); p4.add(separator); p4.add(new Chunk("chapter 4")); // line IS a separator Paragraph p5 = new Paragraph(); p5.add(separator); // line IS a separator + leading Paragraph p6 = new Paragraph(40); p6.add(separator); // separator galore Paragraph p7 = new Paragraph(); p7.setAlignment(Element.ALIGN_JUSTIFIED); for (int i = 0; i < 10; i++) { p7.add(new Chunk("This is a test hippopotamus hippopotamus")); if (i % 4 == 0) p7.add(" hippopotamus hippopotamus hippopotamus hippopotamus"); p7.add(separator); } document.add(p1); document.add(p1); document.add(p2); document.add(p3); document.add(p4); document.add(p5); document.add(p6); document.add(p7); ColumnText ct = new ColumnText(writer.getDirectContent()); ct.addElement(p1); ct.addElement(p1); ct.addElement(p2); ct.addElement(p3); ct.addElement(p4); ct.addElement(p5); ct.addElement(p6); ct.addElement(p7); ct.setSimpleColumn(36, 36, 436, 536); ct.go(); canvas.rectangle(36, 36, 400, 500); canvas.stroke(); document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:questions.separators.TabbedWords2.java
public static void main(String[] args) { Document document = new Document(); try {/*w w w.j a va 2 s . c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); Paragraph p; Chunk tab1 = new Chunk(new VerticalPositionMark(), 100, true); Chunk tab2 = new Chunk(new LineSeparator(), 120, true); Chunk tab3 = new Chunk(new DottedLineSeparator(), 200, true); Chunk tab4 = new Chunk(new VerticalPositionMark(), 240, true); Chunk tab5 = new Chunk(new VerticalPositionMark(), 300, true); PdfContentByte canvas = writer.getDirectContent(); ColumnText column = new ColumnText(canvas); for (int i = 0; i < 40; i++) { p = new Paragraph("TEST"); p.add(tab1); p.add(new Chunk(String.valueOf(i))); p.add(tab2); p.add(new Chunk(String.valueOf(i * 2))); p.add(tab3); p.add(new Chunk(SeparatedWords2.WORDS[39 - i])); p.add(tab4); p.add(new Chunk(String.valueOf(i * 4))); p.add(tab5); p.add(new Chunk(SeparatedWords2.WORDS[i])); column.addElement(p); } column.setSimpleColumn(60, 36, 400, 806); canvas.moveTo(60, 36); canvas.lineTo(60, 806); canvas.moveTo(160, 36); canvas.lineTo(160, 806); canvas.moveTo(180, 36); canvas.lineTo(180, 806); canvas.moveTo(260, 36); canvas.lineTo(260, 806); canvas.moveTo(300, 36); canvas.lineTo(300, 806); canvas.moveTo(360, 36); canvas.lineTo(360, 806); canvas.moveTo(400, 36); canvas.lineTo(400, 806); canvas.stroke(); column.go(); document.setMargins(60, 195, 36, 36); document.newPage(); canvas.moveTo(document.left(), document.bottom()); canvas.lineTo(document.left(), document.top()); canvas.moveTo(document.right(), document.bottom()); canvas.lineTo(document.right(), document.top()); canvas.stroke(); for (int i = 0; i < 40; i++) { p = new Paragraph("TEST"); p.add(tab1); p.add(new Chunk(String.valueOf(i))); p.add(tab2); p.add(new Chunk(String.valueOf(i * 2))); p.add(tab3); p.add(new Chunk(SeparatedWords2.WORDS[39 - i])); p.add(tab4); p.add(new Chunk(String.valueOf(i * 4))); p.add(tab5); p.add(new Chunk(SeparatedWords2.WORDS[i])); document.add(p); } document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:questions.tables.AddTableAsHeaderFooter.java
public void onOpenDocument(PdfWriter writer, Document document) { try {//from w ww.j a v a2s . c om // initializations tpl = writer.getDirectContent().createTemplate(150, 18); Rectangle rect = new Rectangle(0, 0, 150, 18); rect.setBackgroundColor(Color.GRAY); tpl.setBoundingBox(rect); tpl.rectangle(rect); helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); // header headerTable = new PdfPTable(1); PdfPCell cell = new PdfPCell(new Paragraph("Header Text")); headerTable.addCell(cell); headerTable.setTotalWidth(document.right() - document.left()); headerTable.setLockedWidth(true); } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:questions.tables.AddTableAsHeaderFooter.java
public void onEndPage(PdfWriter writer, Document document) { try {//from w w w. java 2s . c om // Header headerTable.writeSelectedRows(0, -1, document.leftMargin(), document.top() + headerTable.getTotalHeight(), writer.getDirectContent()); // Footer PdfPTable footerTable = new PdfPTable(2); PdfPCell cell1 = new PdfPCell(new Phrase("page " + writer.getPageNumber())); footerTable.addCell(cell1); PdfPCell cell2 = new PdfPCell(Image.getInstance(tpl)); footerTable.addCell(cell2); footerTable.setTotalWidth(document.right() - document.left()); footerTable.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent()); } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:questions.tables.TableColumns.java
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate()); try {//from w ww. j a v a 2 s .c om PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); // the content of the columns ColumnText content = new ColumnText(writer.getDirectContent()); PdfPTable items = new PdfPTable(2); items.setWidthPercentage(100); for (int i = 0; i < 100; ++i) { items.addCell("item " + i); items.addCell("some item"); } content.addElement(items); // adding the stuff to the document int column = 0; float height = 0; float[][] x = { { document.left(), document.left() + 380 }, { document.right() - 380, document.right() } }; int status = ColumnText.START_COLUMN; while (ColumnText.hasMoreText(status)) { if (column == 0) { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); table.addCell("EmployeeSheets"); table.addCell("Page " + writer.getPageNumber()); document.add(table); height = table.getTotalHeight(); } content.setSimpleColumn(x[column][0], document.bottom(), x[column][1], document.top() - height - 10); status = content.go(); if (++column >= x.length) { column = 0; document.newPage(); } } } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:questions.tables.TablesWriteSelected.java
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate()); try {/*from www .j av a 2 s.co m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); // the content of the columns PdfPTable items = new PdfPTable(2); items.setTotalWidth(TOTAL_WIDTH); for (int i = 0; i < 100; ++i) { items.addCell("item " + i); items.addCell("some item"); } int rows = items.size(); // adding the stuff to the document int column = 0; int start; int end = 0; int row = 0; float available = 0; float[][] x = { { document.left(), document.left() + TOTAL_WIDTH }, { document.right() - TOTAL_WIDTH, document.right() } }; while (row < rows) { start = row; if (column == 0) { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); table.addCell("EmployeeSheets"); table.addCell("Page " + writer.getPageNumber()); document.add(table); available = document.top() - table.getTotalHeight() - 10 - document.bottom(); } float needed = items.getRowHeight(start); while (needed < available && row < rows) { needed += items.getRowHeight(++row); end = row; } items.writeSelectedRows(start, end, x[column][0], document.bottom() + available, writer.getDirectContent()); if (++column >= x.length) { column = 0; document.newPage(); } } } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }