Example usage for java.io FileOutputStream FileOutputStream

List of usage examples for java.io FileOutputStream FileOutputStream

Introduction

In this page you can find the example usage for java.io FileOutputStream FileOutputStream.

Prototype

public FileOutputStream(FileDescriptor fdObj) 

Source Link

Document

Creates a file output stream to write to the specified file descriptor, which represents an existing connection to an actual file in the file system.

Usage

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("h.pdf"));
    document.open();//from  ww w.  java2  s .  com
    PdfContentByte cb = writer.getDirectContent();
    Graphics2D graphics2D = cb.createGraphics(PageSize.A4.width(), PageSize.A4.height());
    graphics2D.drawString("Hello World", 36, 54);
    graphics2D.dispose();
    document.close();
}

From source file:AddingAWTImagePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from  w w w  . j a v  a2 s. com*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddingAWTImagePDF.pdf"));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage("logo.png");
        Image image = Image.getInstance(awtImage, null);
        image.setAbsolutePosition(100, 500);
        cb.addImage(image);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String inFilename = "infile.gzip";
    GZIPInputStream in = new GZIPInputStream(new FileInputStream(inFilename));

    String outFilename = "outfile";
    OutputStream out = new FileOutputStream(outFilename);

    byte[] buf = new byte[1024];
    int len;/* w w w . ja v a 2 s  .  co  m*/
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }

    in.close();
    out.close();
}

From source file:ArabicTextPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {/*w  ww .  ja  v a  2 s  .co m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ArabicTextPDF.pdf"));
        document.open();
        java.awt.Font font = new java.awt.Font("arial", 0, 18);
        PdfContentByte cb = writer.getDirectContent();
        java.awt.Graphics2D g2 = cb.createGraphicsShapes(PageSize.A4.width(), PageSize.A4.height());
        g2.setFont(font);
        g2.drawString("\u0634\u0627\u062f\u062c\u0645\u0647\u0648\u0645\u0646", 100, 100);
        g2.dispose();
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:ConcatenateFormsPDF.java

public static void main(String[] args) {
    try {// w w  w  . ja v  a2s  .c  o m
        PdfReader reader1 = new PdfReader("SimpleRegistrationForm.pdf");
        PdfReader reader2 = new PdfReader("SimpleRegistrationForm.pdf");
        PdfCopyFields copy = new PdfCopyFields(new FileOutputStream("ConcatenateFormsPDF.pdf"));
        copy.addDocument(reader1);
        copy.addDocument(reader2);
        copy.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:JavaScriptActionPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from w w  w.  jav  a  2  s  . co  m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("JavaScriptActionPDF.pdf"));
        document.open();
        Paragraph p = new Paragraph(
                new Chunk("Click to say Hi").setAction(PdfAction.javaScript("app.alert('Hi');\r", writer)));
        document.add(p);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:ChainedActionsPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*w  w w  . jav  a  2 s  .  c om*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ChainedActionsPDF.pdf"));
        document.open();
        PdfAction action = PdfAction.javaScript("app.alert('Welcome at my site');\r", writer);
        action.next(new PdfAction("http://www.java2s.com"));
        Paragraph p = new Paragraph(new Chunk("Click to go to a website").setAction(action));
        document.add(p);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:TemplatesDrawPDF.java

public static void main(String[] args) {
    Document document = new Document();

    try {//from w w w. j  ava  2 s  . c  o  m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TemplatesDrawPDF.pdf"));
        document.open();

        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate template = cb.createTemplate(500, 200);
        template.moveTo(0, 200);
        template.lineTo(500, 0);
        template.stroke();
        template.circle(250f, 100f, 80f);
        template.stroke();

        cb.addTemplate(template, 0, 0);

        document.newPage();
        cb.addTemplate(template, 2, 0, 0, 2, -200, 400);
    } 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(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();//from   www. jav a2 s.  c  o  m
    PdfPTable table = new PdfPTable(3);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell("the quick brown fox");
    table.addCell("the quick brown fox");

    document.add(table);

    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  .jav  a  2  s  .  com*/
    String text = "\u5e73\u548C";
    PdfContentByte cb = writer.getDirectContent();
    PdfTemplate tp = cb.createTemplate(100, 50);
    Graphics2D g2 = tp.createGraphicsShapes(100, 50);
    java.awt.Font font = new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 12);
    g2.setFont(font);
    g2.drawString(text, 0, 40);
    g2.dispose();
    cb.addTemplate(tp, 36, 780);
    document.close();
}