[Reprint]java implement Word to PDF

Source: Internet
Author: User

Recently encountered a project need to turn Word into a PDF, Baidu has a lot of options on the Internet, such as virtual printing, to Word extension, etc., these programs rely on MS Word program, in Java code also have to use such as Jacob or jcom Java COM bridge , so that server development is limited to the win platform, and it is cumbersome to deploy. Later in a forum saw a openoffice+jodconverter conversion program, you can complete the conversion of Word to PDF work, server development needs to install OpenOffice, But the need for additional operations--needing a openoffice service on one of the ports on the server development--is a bit cumbersome and seemingly less secure to deploy.
The occasional opportunity to discover the Pageoffice component also enables Word to PDF functionality. And instead of simply converting Word to PDF, you can also support dynamically populating the data into a Word template file and then into a PDF file.
The following are the official website:

  

The core code that calls the Pageoffice component's FileMaker object implementation to dynamically populate the data into a Word template and convert it to PDF is as follows:

    Filemakerctrl Fmctrl = new Filemakerctrl (request);    Fmctrl.setserverpage (Request.getcontextpath () + "/poserver.zz");    Worddocument doc = new worddocument ();    Doc.opendataregion ("Po_company"). SetValue ("A Beijing Company Limited");//Assign data to the data area, that is, fill in the corresponding position in the template    fmctrl.setsavefilepage ("/ Savepdf "); Save PDF Action or Requestmapping method    Fmctrl.setwriter (DOC);    Fmctrl.filldocumentaspdf ("Doc/template.doc", Documentopentype.word, "123.pdf");//fill in the Word template and convert to PDF
Save the code for the action or Requestmapping method (/savepdf) of the PDF:
    Filesaver fs = new Filesaver (request, response);    Fs.savetofile (Request.getsession (). Getservletcontext (). Getrealpath ("Doc") + "/" + fs.getfilename ());    Fs.close ();

Sample source and Effect: http://www.zhuozhengsoft.com/dowm/, download Pageoffice for Java, unzip, copy the Samples4 folder to the WebApps directory of Tomcat, Access:/http localhost:8080/samples4/index.html, view example: Two, 34, FileMaker convert a single document to PDF (for example in Word)

[Reprint]java for Word to PDF

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.