/**
* @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");
}
}
'언어 > JAVA' 카테고리의 다른 글
[JAVA] CRON 만들기 (1) | 2021.08.09 |
---|---|
[JVAA] 특정 날짜 이전 위치 폴더 파일 삭제 (0) | 2020.03.18 |
[JAVA] 시분초 밀리 세컨드까지 값 가져오기. (0) | 2020.03.18 |
[JAVA] 여러 PDF 합치기 (0) | 2020.03.18 |
[JAVA] PDF 페이지 중간 삭제 (0) | 2020.03.18 |