List of usage examples for com.lowagie.text Document newPage
public boolean newPage()
From source file:questions.separators.LineSeparator2.java
public static void main(String[] args) { Document document = new Document(); try {//from ww w . java 2 s . c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); VerticalPositionMark separator = new LineSeparator(1, 80, Color.RED, Element.ALIGN_RIGHT, -2); ColumnText column = new ColumnText(writer.getDirectContent()); for (int i = 0; i < 5; i++) { column.addElement(StarSeparators.TEXT); column.addElement(separator); } column.setSimpleColumn(36, 36, 295, 806); column.go(); column.setSimpleColumn(300, 36, 559, 806); column.go(); document.newPage(); for (int i = 0; i < 10; i++) { document.add(StarSeparators.TEXT); document.add(separator); } document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:questions.separators.LineSeparator3.java
public static void main(String[] args) { Document document = new Document(); try {//from w ww . j a v a2s . c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); Paragraph p = new Paragraph(StarSeparators.TEXT); VerticalPositionMark separator = new LineSeparator(1, 100, Color.RED, Element.ALIGN_RIGHT, -2); p.add(separator); ColumnText column = new ColumnText(writer.getDirectContent()); for (int i = 0; i < 5; i++) { column.addElement(p); } column.setSimpleColumn(36, 36, 295, 806); column.go(); column.setSimpleColumn(300, 36, 559, 806); column.go(); document.newPage(); for (int i = 0; i < 10; i++) { document.add(p); } document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:questions.separators.PositionedMarks.java
public static void main(String[] args) { Document document = new Document(); try {/*from w w w .j ava2 s .c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); Paragraph p = new Paragraph(StarSeparators.TEXT); p.add(0, new PositionedMarks(true)); p.add(new PositionedMarks(false)); ColumnText column = new ColumnText(writer.getDirectContent()); for (int i = 0; i < 5; i++) { column.addElement(p); } column.setSimpleColumn(36, 36, 275, 806); column.go(); column.setSimpleColumn(320, 36, 559, 806); column.go(); document.newPage(); for (int i = 0; i < 10; i++) { document.add(p); } document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:questions.separators.StarSeparators.java
public static void main(String[] args) { Document document = new Document(); try {//from www. j a va 2s .c om PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); Paragraph stars = new Paragraph(20); stars.add(new Chunk(new StarSeparators())); stars.setSpacingAfter(30); ColumnText column = new ColumnText(writer.getDirectContent()); for (int i = 0; i < 5; i++) { column.addElement(TEXT); column.addElement(stars); } column.setSimpleColumn(36, 36, 295, 806); column.go(); column.setSimpleColumn(300, 36, 559, 806); column.go(); document.newPage(); for (int i = 0; i < 50; i++) { document.add(TEXT); document.add(stars); } document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:questions.separators.TabbedWords1.java
public static void main(String[] args) { Document document = new Document(); try {// w ww. ja va 2 s. co m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); Paragraph p; Chunk tab1 = new Chunk(new VerticalPositionMark(), 100); Chunk tab2 = new Chunk(new LineSeparator(), 120); Chunk tab3 = new Chunk(new DottedLineSeparator(), 200); Chunk tab4 = new Chunk(new VerticalPositionMark(), 250); Chunk tab5 = new Chunk(new VerticalPositionMark(), 300); 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(310, 36); canvas.lineTo(310, 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(); 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.separators.TabbedWords2.java
public static void main(String[] args) { Document document = new Document(); try {//from ww w .j a v a2s . c om 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.stamppages.PageXofYRightAligned.java
public static void main(String[] args) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/* w ww . j a v a2s . c o m*/ Document document = new Document(); PdfWriter.getInstance(document, baos); document.open(); BufferedReader reader = new BufferedReader(new FileReader(RESOURCE)); String line; Paragraph p; while ((line = reader.readLine()) != null) { p = new Paragraph(line); p.setAlignment(Element.ALIGN_JUSTIFIED); document.add(p); document.newPage(); } reader.close(); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } try { PdfReader reader = new PdfReader(baos.toByteArray()); int n = reader.getNumberOfPages(); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfContentByte page; Rectangle rect; BaseFont bf = BaseFont.createFont(); for (int i = 1; i < n + 1; i++) { page = stamper.getOverContent(i); rect = reader.getPageSizeWithRotation(i); page.beginText(); page.setFontAndSize(bf, 12); page.showTextAligned(Element.ALIGN_RIGHT, "page " + i + " of " + n, rect.getRight(36), rect.getTop(32), 0); page.endText(); } stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.stamppages.RemoveAttachmentAnnotations.java
public static void createPdfWithAttachments() throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESOURCE)); document.open();/*from w w w . ja va2 s .co m*/ document.add(new Paragraph("page 1")); writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 780f, 120f, 800f), "This is some text", "some text".getBytes(), null, "some.txt")); writer.addAnnotation(PdfAnnotation.createText(writer, new Rectangle(100f, 750f, 120f, 770f), "Help", "This Help annotation was made with 'createText'", false, "Help")); document.newPage(); document.add(new Paragraph("page 2")); document.newPage(); document.add(new Paragraph("page 3")); PdfFileSpecification fs1 = PdfFileSpecification.fileEmbedded(writer, TXT, "caesar.txt", null); writer.addAnnotation( PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 780f, 120f, 800f), "Caesar", fs1)); PdfFileSpecification fs2 = PdfFileSpecification.fileEmbedded(writer, IMG, "1t3xt.gif", null); writer.addAnnotation( PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 750f, 120f, 770f), "1t3xt", fs2)); document.close(); }
From source file:questions.tables.TableColumns.java
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate()); try {//from w w w .ja va 2 s . co m 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 {/*w ww . j a v 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(); }