To convert a Word file to a PDF file using docx4j:
Public Static voidConvertdocxtopdf (String Docxfilepath, String pdfpath)throwsException {outputstream os=NULL; Try { //Loading FilesFile docx =NewFile (Docxfilepath); InputStream is=NewFileInputStream (docx); Wordprocessingmlpackage Mlpackage=Wordprocessingmlpackage.load (IS); //Font ConversionsMapper Fontmapper =NewIdentityplusmapper (); Fontmapper.put ("XXFarEastFont-Xingkai", Physicalfonts.get ("Stxingkai")); Fontmapper.put ("XXFarEastFont-Imitation", Physicalfonts.get ("Stfangsong")); Fontmapper.put ("XXFarEastFont-Arial", Physicalfonts.get ("Stsong")); Fontmapper.put ("XXFarEastFont-Physicalfonts.get", "Stzhongsong")); Fontmapper.put ("Official Script", Physicalfonts.get ("Lisu")); Fontmapper.put ("Song Body", Physicalfonts.get ("SimSun")); Fontmapper.put ("Microsoft Jas Black", Physicalfonts.get ("Microsoft Yahei")); Fontmapper.put ("Blackbody", Physicalfonts.get ("Simhei")); Fontmapper.put ("Italics", Physicalfonts.get ("Kaiti")); Fontmapper.put ("New song Body", Physicalfonts.get ("Nsimsun")); Fontmapper.put ("Song-Body Extension", Physicalfonts.get ("SIMSUN-EXTB")); Fontmapper.put ("Imitation", Physicalfonts.get ("Fangsong")); Fontmapper.put ("Imitation _gb2312", Physicalfonts.get ("fangsong_gb2312")); Fontmapper.put ("Young Circle", Physicalfonts.get ("Youyuan")); Mlpackage.setfontmapper (Fontmapper); //OS =NewFileOutputStream (Pdfpath); Fosettings fosettings=docx4j.createfosettings (); Fosettings.setwmlpackage (Mlpackage); Docx4j.tofo (fosettings, OS, docx4j.flag_export_prefer_xsl); } Catch(Exception ex) {ex.printstacktrace (); } finally{ioutils.closequietly (OS); } }
Website address: https://www.docx4java.org/forums/
Support for Word, Excel, PPT:
Convert Word to PDF, dependent on Plutext, official address: http://converter-eval.plutext.com/
Plutext is a commercial software package with a 180-day trial.
You can also use FO, this way for free.
webapp.docx4java.org/onlinedemo/docx_to_pdf.html?_ga=2.226968541.1700223194.1521458163-1699339587.1517224689
Java converting Word files to PDF files