Java converting Word files to PDF files

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.