怎样利用iText把生成出的PDF变成压缩包
展开全部
官方demo
public class HelloZip {
/** Path to the resulting PDF file. */
public static final String RESULT
= "results/part1/chapter01/hello.zip";
/**
* Creates a zip file with five PDF documents:
* hello1.pdf to hello5.pdf
* @param args no arguments needed
*/
public static void main(String[] args)
throws DocumentException, IOException {
// creating a zip file with different PDF documents
ZipOutputStream zip =
new ZipOutputStream(new FileOutputStream(RESULT));
for (int i = 1; i <= 1; i++) {
ZipEntry entry = new ZipEntry("hello_" + i + ".pdf");
zip.putNextEntry(entry);
// step 1
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, zip);
writer.setCloseStream(false);
// step 3
document.open();
// step 4
document.add(new Paragraph("Hello " + i));
// step 5
document.close();
zip.closeEntry();
}
zip.close();
}
}
public class HelloZip {
/** Path to the resulting PDF file. */
public static final String RESULT
= "results/part1/chapter01/hello.zip";
/**
* Creates a zip file with five PDF documents:
* hello1.pdf to hello5.pdf
* @param args no arguments needed
*/
public static void main(String[] args)
throws DocumentException, IOException {
// creating a zip file with different PDF documents
ZipOutputStream zip =
new ZipOutputStream(new FileOutputStream(RESULT));
for (int i = 1; i <= 1; i++) {
ZipEntry entry = new ZipEntry("hello_" + i + ".pdf");
zip.putNextEntry(entry);
// step 1
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, zip);
writer.setCloseStream(false);
// step 3
document.open();
// step 4
document.add(new Paragraph("Hello " + i));
// step 5
document.close();
zip.closeEntry();
}
zip.close();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询