
pdf.converter.zip.ZipCreator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pdf-converter Show documentation
Show all versions of pdf-converter Show documentation
A Java library to convert .pdf files into .txt, .jpg, .png, .epub and .zip formats.
package pdf.converter.zip;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import pdf.converter.img.ImageFileExtension;
import pdf.converter.img.ImgCreator;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ZipCreator {
// private static final Logger log = LoggerFactory.getLogger(ZipCreator.class);
public void create(File imgsDir, File output) throws IOException {
pack(imgsDir.getAbsolutePath(), output.getAbsolutePath());
}
private static void pack(String sourceDirPath, String zipFilePath) throws IOException {
Path p = Files.createFile(Paths.get(zipFilePath));
try (ZipOutputStream zs = new ZipOutputStream(Files.newOutputStream(p))) {
Path pp = Paths.get(sourceDirPath);
Files.walk(pp)
.filter(path -> !Files.isDirectory(path))
.forEach(path -> {
ZipEntry zipEntry = new ZipEntry(pp.relativize(path).toString());
try {
zs.putNextEntry(zipEntry);
zs.write(Files.readAllBytes(path));
zs.closeEntry();
} catch (Exception e) {
// log.warn("Failed to create zip file", e);
}
});
}
}
public static void main(String[] args) {
new ImgCreator().process(new File("/home/joze/Downloads/ASEFlogo_popravljen.pdf"), new File("/home/joze/Downloads"), 300, 800, 800, ImageFileExtension.PNG);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy