/**
* @param orgFilePath 기존 파일 경로/명
* @param filePath // 바꿀 파일 경로/명
*/
public static void tifToPDF(String orgFilePath,String filePath){
String imgeFilename = orgFilePath;
Document document = new Document();
try {
PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream(filePath));
writer.setStrictImageSequence(true);
document.open();
Image image;
RandomAccessFileOrArray ra = new RandomAccessFileOrArray(imgeFilename);
int pages = TiffImage.getNumberOfPages(ra);
for (int i = 1; i <= pages; i++) {
image = TiffImage.getTiffImage(ra, i);
Rectangle pageSize = new Rectangle(image.getWidth(),
image.getHeight());
document.setPageSize(pageSize);
document.add(image);
document.newPage();
}
document.close();
} catch (Exception e) {
e.printStackTrace();
}finally{
if(document!=null)document.close();
}
}
/**
* @param orgFilePath jpg full 경로
* @param filePath pdf full경로
*/
public static void pngToPdf(String orgFilePath,String filePath){
if (!filePath.endsWith(".pdf")){
System.err.println("Last argument must be the destination .pdf file");
System.exit(1);
}
PDDocument doc = new PDDocument();
try{
PDPage page = new PDPage();
doc.addPage(page);
PDImageXObject pdImage = PDImageXObject.createFromFile(orgFilePath, doc);
PDPageContentStream contents = new PDPageContentStream(doc, page);
contents.drawImage(pdImage, 0, 0, 612, 796);
contents.close();
doc.save(filePath);
}catch(Exception e){
e.printStackTrace();
}finally{
try {
doc.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("fin");
}
}