현재 Apache poi를 사용하여 Java 프로젝트를 진행 중입니다. 내 프로젝트에서 doc 파일을 pdf 파일로 변환하고 싶습니다. 변환은 성공적으로 완료되었지만 텍스트 스타일이나 텍스트 색상이 아닌 pdf로 된 텍스트 만 가져옵니다. 내 PDF 파일이 검은 색으로 보입니다. & 흰색입니다. 내 문서 파일은 색칠되어 있고 다른 텍스트 스타일을 사용합니다. Apache POI HWPF - pdf로 변환하는 doc 파일의 문제
이
은POIFSFileSystem fs = null;
Document document = new Document();
try {
System.out.println("Starting the test");
fs = new POIFSFileSystem(new FileInputStream("/document/test2.doc"));
HWPFDocument doc = new HWPFDocument(fs);
WordExtractor we = new WordExtractor(doc);
OutputStream file = new FileOutputStream(new File("/document/test.pdf"));
PdfWriter writer = PdfWriter.getInstance(document, file);
Range range = doc.getRange();
document.open();
writer.setPageEmpty(true);
document.newPage();
writer.setPageEmpty(true);
String[] paragraphs = we.getParagraphText();
for (int i = 0; i < paragraphs.length; i++) {
org.apache.poi.hwpf.usermodel.Paragraph pr = range.getParagraph(i);
// CharacterRun run = pr.getCharacterRun(i);
// run.setBold(true);
// run.setCapitalized(true);
// run.setItalic(true);
paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n", "");
System.out.println("Length:" + paragraphs[i].length());
System.out.println("Paragraph" + i + ": " + paragraphs[i].toString());
// add the paragraph to the document
document.add(new Paragraph(paragraphs[i]));
}
System.out.println("Document testing completed");
} catch (Exception e) {
System.out.println("Exception during test");
e.printStackTrace();
} finally {
// close the document
document.close();
}
}
좀 도와주세요, 내 코드입니다.
Thnx.