import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Paths; import org.apache.poi.xwpf.converter.pdf.PdfConverter; import org.apache.poi.xwpf.converter.pdf.PdfOptions; import org.apache.poi.xwpf.usermodel.XWPFDocument; public class Main { /** * @param args the command line arguments * @throws java.io.IOException */ public static void main(String[] args) throws IOException { String docPath = "C:\Users\Administrator\Documents\Tencent Files\815703271\FileRecv\MobileFile\shangedaijiekuanxieyi.docx"; String pdfPath = "C:\Users\Administrator\Documents\Tencent Files\815703271\FileRecv\MobileFile\shangedaijiekuanxieyi.pdf"; XWPFDocument document; try (InputStream doc = Files.newInputStream(Paths.get(docPath))) { document = new XWPFDocument(doc); } PdfOptions options = PdfOptions.create(); try (OutputStream out = Files.newOutputStream(Paths.get(pdfPath))) { PdfConverter.getInstance().convert(document, out, options); } } }