List of usage examples for java.io FileOutputStream FileOutputStream
public FileOutputStream(FileDescriptor fdObj)
From source file:FillCirclesPDF.java
public static void main(String[] args) { Document document = new Document(); try {/*from w ww. ja v a2s . c om*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("FillCirclesPDF.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); cb.setRGBColorFill(0xFF, 0x00, 0x00); cb.circle(250.0f, 500.0f, 200.0f); cb.circle(250.0f, 500.0f, 150.0f); cb.circle(350.0f, 300.0f, 150.0f); cb.fillStroke(); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); }
From source file:UnderlinedTextPDF.java
public static void main(String[] args) { Document document = new Document(); try {/*from w ww .j av a 2s . co m*/ PdfWriter.getInstance(document, new FileOutputStream("UnderlinedTextPDF.pdf")); document.open(); Chunk underlined = new Chunk("underlined"); underlined.setUnderline(0.2f, -2f); Paragraph p = new Paragraph("The following chunk is "); p.add(underlined); document.add(p); } catch (Exception ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { FileInputStream inFile = new FileInputStream(args[0]); FileOutputStream outFile = new FileOutputStream(args[1]); FileChannel inChannel = inFile.getChannel(); FileChannel outChannel = outFile.getChannel(); ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024); int bytesRead = 0; while (bytesRead >= 0 || buffer.hasRemaining()) { if (bytesRead != -1) bytesRead = inChannel.read(buffer); buffer.flip();// w ww . jav a 2 s.c o m outChannel.write(buffer); buffer.compact(); } inChannel.close(); outChannel.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); document.open();/*from w w w . j a va2s . co m*/ Chunk c = new Chunk("this is a test"); float w = c.getWidthPoint(); Paragraph p = new Paragraph("The width of the chunk: '"); p.add(c); p.add("' is "); p.add(String.valueOf(w)); p.add(" points or "); p.add(String.valueOf(w / 72f)); p.add(" inches or "); p.add(String.valueOf(w / 72f * 2.54f)); p.add(" cm."); document.add(p); document.add(Chunk.NEWLINE); document.add(c); document.close(); }
From source file:FontFactoryStylesPDF.java
public static void main(String[] args) { Document document = new Document(); try {/*from w ww . j av a2s . c o m*/ PdfWriter.getInstance(document, new FileOutputStream("FontFactoryStylesPDF.pdf")); document.open(); FontFactory.register("c:\\windows\\fonts\\arial.ttf"); Phrase myPhrase = new Phrase("This is font family Arial ", FontFactory.getFont("Arial", 8)); document.add(myPhrase); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); }
From source file:StrokeClosePDF.java
public static void main(String[] args) { Document document = new Document(); try {//from w ww . ja va 2 s.co m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("StrokeClosePDF.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); cb.setLineWidth(10f); cb.setRGBColorStrokeF(0f, 255f, 0f); cb.moveTo(100, 700); cb.lineTo(200, 800); cb.lineTo(200f, 250f); cb.lineTo(400f, 150f); cb.closePathFillStroke(); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); document.open();/* w w w .j a va2 s . c om*/ Chunk c = new Chunk("this is a test"); float w = c.getWidthPoint(); Paragraph p = new Paragraph("The width of the chunk: '"); p.add(c); p.add("' is "); p.add(String.valueOf(w)); p.add(" points or "); p.add(String.valueOf(w / 72f)); p.add(" inches or "); p.add(String.valueOf(w / 72f * 2.54f)); p.add(" cm."); document.add(p); document.add(c); c.setHorizontalScaling(0.5f); document.add(c); document.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); document.open();//from w w w. j a v a 2 s .c o m writer.addJavaScript("function saySomething(s) {app.alert(s)}", false); writer.setAdditionalAction(PdfWriter.DOCUMENT_CLOSE, PdfAction.javaScript("saySomething('hi');\r", writer)); document.add(new Paragraph("PDF document with a JavaScript function.")); document.close(); }
From source file:InputOutputDemoObjectBinaryFile.java
public static void main(String[] a) throws Exception { //Write an object or array to binary file "java2sObject.dat": ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("java2sObject.dat")); oos.writeObject(new int[] { 2, 3, 5, 7, 11 }); oos.close();/* www . j a v a 2s. c o m*/ //Read objects or arrays from binary file "o.dat": ObjectInputStream ois = new ObjectInputStream(new FileInputStream("java2sObject.dat")); int[] ia = (int[]) (ois.readObject()); System.out.println(ia[0] + "," + ia[1] + "," + ia[2] + "," + ia[3] + "," + ia[4]); }
From source file:CopyPDFFileAndAddMetaData.java
public static void main(String[] args) { try {/* w w w . ja v a 2 s .c o m*/ PdfReader reader = new PdfReader("YourOwnPDF.pdf"); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("NewPDFFileFromPdfStamper.pdf")); HashMap<String, String> moreInfo = new HashMap<String, String>(); moreInfo.put("Author", "YourName"); moreInfo.put("Title", "YourTitle"); moreInfo.put("Subject", "YourSubject"); stamp.setMoreInfo(moreInfo); stamp.close(); } catch (Exception de) { de.printStackTrace(); } }