Java Zip dosyası oluşturma kodu kullanımı örneği (Java generate Zip file code usage example)

itextpdf” kütüphanesini kullanarak PDF dosyası ekleyeceğiz. [code language=”java”] package net.yazilimcity.java.pdf.test; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; public class ZipUtil { public static void main(String[] args) throws DocumentException, IOException { //String result = "hello.zip"; // on application root path String result = "/home/oguzkinik/temp/hello.zip"; // on machine target path which application running ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(result)); for (int i=0; i<2; i++) { // zipt entry file name ZipEntry entry = new ZipEntry("hello_" + i + ".pdf"); // put entry to zip zip.putNextEntry(entry); // document generate with itextpdf Document document = new Document(); // write document entry to zip PdfWriter writer = PdfWriter.getInstance(document, zip); writer.setCloseStream(false); document.open(); document.add(new Paragraph("Hello " + i)); document.close(); // close current entry for zip zip.closeEntry(); } zip.close(); } } [/code]]]>

Leave a Reply

Your email address will not be published. Required fields are marked *