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 с правильным форматом и выравниванием.