List of usage examples for java.lang Exception printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String[] args) { try {/*from ww w . j a v a2s. c om*/ OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os); // create a new FileInputStream to read what we write FileInputStream in = new FileInputStream("test.txt"); // write something in the file writer.write(70); // flush the stream writer.flush(); // get and print the encoding for this stream System.out.println(writer.getEncoding()); // read what we write System.out.println((char) in.read()); writer.close(); os.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:NamedActionsPDF.java
public static void main(String[] args) { Document document = new Document(PageSize.A4, 50, 50, 50, 50); try {//w ww. java 2 s .c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("NamedActionsPDF.pdf")); document.open(); Paragraph p = new Paragraph( new Chunk("Click to print").setAction(new PdfAction(PdfAction.PRINTDIALOG))); p.add(new Phrase(new Chunk("First Page").setAction(new PdfAction(PdfAction.FIRSTPAGE)))); p.add(new Phrase(new Chunk("Prev Page").setAction(new PdfAction(PdfAction.PREVPAGE)))); p.add(new Phrase(new Chunk("Next Page").setAction(new PdfAction(PdfAction.NEXTPAGE)))); p.add(new Phrase(new Chunk("Last Page").setAction(new PdfAction(PdfAction.LASTPAGE)))); for (int i = 1; i <= 10; ++i) { document.add(new Paragraph("This is page " + i)); document.add(new Paragraph(Chunk.NEWPAGE)); document.add(p); document.newPage(); } } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:TwoOnOnePDF.java
public static void main(String[] args) { System.out.println(""); try {// www. j a va2 s .c o m PdfReader reader = new PdfReader("YourOwnPDF.pdf"); int n = reader.getNumberOfPages(); Rectangle psize = reader.getPageSize(1); float width = psize.height(); float height = psize.width(); Document document = new Document(new Rectangle(width, height)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TwoOnOnePDF.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); document.newPage(); PdfImportedPage page1 = writer.getImportedPage(reader, 1); cb.addTemplate(page1, .5f, 0, 0, .5f, 60, 120); document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:CellEventsPDF.java
License:asdf
public static void main(String[] args) { Document document = new Document(PageSize.A4, 50, 50, 50, 50); try {// www . ja v a 2s . co m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("CellEventsPDF.pdf")); document.open(); PdfPTable table = new PdfPTable(1); PdfPCell cell = new PdfPCell(); cell.setCellEvent(new MyCellEvent()); cell.setPhrase(new Phrase("asdfasdf")); table.addCell(cell); table.setTotalWidth(300); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:ShadingPatternPDF.java
public static void main(String[] args) { Document document = new Document(PageSize.A4, 50, 50, 50, 50); try {/*from w w w . j a v a2s . co m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ShadingPatternPDF.pdf")); document.open(); PdfShading shading = PdfShading.simpleAxial(writer, 100, 100, 400, 100, Color.red, Color.cyan); PdfShadingPattern shadingPattern = new PdfShadingPattern(shading); PdfContentByte cb = writer.getDirectContent(); cb.setShadingFill(shadingPattern); cb.circle(50, 50, 50); cb.stroke(); PdfShading shadingR = PdfShading.simpleRadial(writer, 200, 500, 50, 300, 500, 100, new Color(255, 247, 148), new Color(247, 138, 107), false, false); cb.paintShading(shadingR); document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:SpotColorsForTemplatePDF.java
public static void main(String[] args) { Document document = new Document(); try {//from ww w . j a v a 2s. c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("SpotColorsForTemplatePDF.pdf")); document.open(); PdfSpotColor spc_g = new PdfSpotColor("PANTONE 100 CV", 0.5f, new GrayColor(0.9f)); PdfContentByte cb = writer.getDirectContent(); PdfTemplate t = cb.createTemplate(500f, 500f); t.setColorStroke(new SpotColor(spc_g, .5f)); t.setLineWidth(10f); t.rectangle(100, 10, 100, 100); t.stroke(); cb.addTemplate(t, -1.0f, 0.00f, 0.00f, -1.0f, 550f, 550f); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:MainClass.java
public static void main(String[] args) { try {//w w w. ja v a2s .c om File aFile = new File("test.txt"); FileOutputStream outputFile = null; outputFile = new FileOutputStream(aFile, true); FileChannel outChannel = outputFile.getChannel(); ByteBuffer buf = ByteBuffer.allocate(200); buf.putInt(10).asCharBuffer().put("www.java2s.com"); buf.position(10).flip(); outChannel.write(buf); buf.clear(); outputFile.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:BookmarksPDF.java
public static void main(String[] args) { Document document = new Document(PageSize.A6); try {//from ww w .ja v a 2 s . c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("BookmarksPDF.pdf")); writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); document.open(); writer.setPageEvent(new BookmarksPDF()); document.add(new Paragraph("Text", new Font(Font.HELVETICA, 12))); document.newPage(); document.add(new Paragraph("Text Text", new Font(Font.HELVETICA, 24))); document.newPage(); document.add(new Paragraph("Text Text Text", new Font(Font.HELVETICA, 36))); document.newPage(); document.add(new Paragraph("Text Text Text Text", new Font(Font.HELVETICA, 48))); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:MainClass.java
public static void main(String[] args) { Connection connection = null; Statement statement = null;/*from ww w .j a va 2 s . c o m*/ try { Class.forName("org.gjt.mm.mysql.Driver").newInstance(); String url = "jdbc:mysql://localhost/mysql"; connection = DriverManager.getConnection(url, "username", "password"); statement = connection.createStatement(); String hrappSQL = "CREATE DATABASE hrapp"; statement.executeUpdate(hrappSQL); } catch (Exception e) { e.printStackTrace(); } finally { if (statement != null) { try { statement.close(); } catch (SQLException e) { } } if (connection != null) { try { connection.close(); } catch (SQLException e) { } } } }
From source file:SimpleTableTwoCellsInARowPDF.java
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate(), 50, 50, 50, 50); try {/*from w w w . j a va 2 s.co m*/ PdfWriter.getInstance(document, new FileOutputStream("SimpleTableTwoCellsInARowPDF.pdf")); document.open(); SimpleTable table = new SimpleTable(); SimpleCell row = new SimpleCell(SimpleCell.ROW); SimpleCell cell = new SimpleCell(SimpleCell.CELL); cell.add(new Paragraph("B")); cell.setWidth(100f); row.add(cell); cell = new SimpleCell(SimpleCell.CELL); cell.add(new Paragraph("A")); cell.setWidth(50f); row.add(cell); table.addElement(row); document.add(table); } catch (Exception e) { e.printStackTrace(); } document.close(); }