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:Skew_450.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from   ww  w. j av a 2s.co  m
        PdfWriter.getInstance(document, new FileOutputStream("Skew_450.pdf"));

        document.open();

        Chunk chunk = new Chunk("This is a chunk.");
        chunk.setSkew(-45f, 0f);
        document.add(chunk);

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:ImagesGIFPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from w ww. ja  va  2  s.  c om
        PdfWriter.getInstance(document, new FileOutputStream("ImagesGIFPDF.pdf"));
        document.open();

        document.add(new Paragraph("load a gif image file"));
        Image img = Image.getInstance("logo.gif");
        document.add(img);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:Main.java

public static void main(String[] args) {

    Path copy_from_4 = Paths.get("C:/tutorial/Java/JavaFX", "tutor.txt");
    Path copy_to_4 = Paths.get("C:/tutorial/Java/Swing", "tutor.txt");
    try (OutputStream os = new FileOutputStream(copy_to_4.toFile())) {

        Files.copy(copy_from_4, os);

    } catch (IOException e) {
        System.err.println(e);/*from  w  ww . ja  v a2 s.c  om*/
    }

}

From source file:AnnotatedImagePDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {//from   w ww.  ja  v  a2s.  c  om
        PdfWriter.getInstance(document, new FileOutputStream("AnnotatedImagePDF.pdf"));

        document.open();

        Image jpeg = Image.getInstance("logo.png");
        jpeg.setAnnotation(new Annotation("picture", "This is the logo", 0, 0, 0, 0));
        jpeg.setAbsolutePosition(100f, 550f);
        document.add(jpeg);

    } catch (Exception de) {
        de.printStackTrace();
    }
    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("clipping_path.pdf"));
    document.open();//from w  w  w  .  ja  v a  2s  . c o m
    Image img = Image.getInstance("dog.jpg");
    float w = img.scaledWidth();
    float h = img.scaledHeight();
    PdfContentByte cb = writer.getDirectContent();

    PdfTemplate tp1 = cb.createTemplate(w, h);
    img.setAbsolutePosition(0, 0);
    tp1.roundRectangle(0, 0, w, h, 10);
    tp1.clip();
    tp1.newPath();
    tp1.addImage(img);
    cb.addTemplate(tp1, 36, 420);

    document.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] filenames = new String[] { "filename1", "filename2" };
    byte[] buf = new byte[1024];
    String outFilename = "outfile.zip";
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));

    for (int i = 0; i < filenames.length; i++) {
        FileInputStream in = new FileInputStream(filenames[i]);
        out.putNextEntry(new ZipEntry(filenames[i]));
        int len;/*from   w ww .j av  a 2 s  .c  o  m*/
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        out.closeEntry();
        in.close();
    }
    out.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    PdfReader reader = new PdfReader("1.pdf");
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("my.pdf"), PdfWriter.VERSION_1_5);
    stamper.setFullCompression();/*  ww  w. j av a 2 s . com*/
    stamper.close();

    reader = new PdfReader("1.pdf");
    stamper = new PdfStamper(reader, new FileOutputStream("myDecompressed.pdf"), '1');
    Document.compress = false;
    int total = reader.getNumberOfPages() + 1;
    for (int i = 1; i < total; i++) {
        reader.setPageContent(i, reader.getPageContent(i));
    }
    stamper.close();

    showFileSize("1.pdf");
    showFileSize("my.pdf");
    showFileSize("myDecompressed.pdf");

}

From source file:ChunkWidthPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from   w w  w. java2 s  .c o  m*/
        PdfWriter.getInstance(document, new FileOutputStream("ChunkWidthPDF.pdf"));
        document.open();

        Chunk c = new Chunk("Text Text Text Text Text Text Text Text Text Text");
        float w = c.getWidthPoint();
        System.out.println(
                "The width of the chunk: is " + String.valueOf(w) + " points or " + w / 72f + " inches.");
        document.add(c);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:GStatePDF.java

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

    try {/*  w  w  w  .j a v a 2  s. c  o m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("GStatePDF.pdf"));
        document.open();

        PdfContentByte cb = writer.getDirectContent();
        PdfGState gs = new PdfGState();
        gs.setFillOpacity(0.5f);
        cb.setGState(gs);

        cb.setColorFill(Color.red);
        cb.circle(360.0f, 500.0f, 250.0f);
        cb.fill();
        gs.setFillOpacity(0.2f);
        cb.setGState(gs);
        cb.setColorFill(Color.blue);
        cb.circle(460.0f, 500.0f, 100.0f);
        cb.fill();
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:ImageSequencePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from   w ww.  j  a v  a  2 s. com*/
        PdfWriter.getInstance(document, new FileOutputStream("ImageSequencePDF.pdf"));
        document.open();

        Image image = Image.getInstance("logo.png");
        for (int i = 0; i < 20; i++) {
            document.add(image);
        }

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}