【发布时间】:2018-05-24 06:16:01
【问题描述】:
public class CreatePdf {
public static void main(String[] args) {
CreatePdf pdf = new CreatePdf();
System.out.println("start");
pdf.ConvertToPDF("D:\\doctopdf.docx", "D:\\Test1.pdf");
}
public void ConvertToPDF(String docPath, String pdfPath) {
try {
InputStream doc = new FileInputStream(new File(docPath));
XWPFDocument document = new XWPFDocument(doc);
PdfOptions options = PdfOptions.create();
OutputStream out = new FileOutputStream(new File(pdfPath));
PdfConverter.getInstance().convert(document, out, options);
System.out.print("Done");
/*}catch(FileNotFoundException ex){
System.out.print(ex.getMessage());*/
}catch(IOException ex){
System.out.print(ex.getMessage());
}
}
}
我的要求是创建一个 java 代码,将现有的 docx 转换为具有正确格式和对齐方式的 pdf。
【问题讨论】:
-
你在哪里调用那个方法?
-
@XtremeBaumer,显然这是从库代码中抛出的
标签: java pdf apache-poi