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:
New Filemakerctrl (request); Fmctrl.setserverpage (Request.getcontextpath ()+ "/poserver.zz"); New worddocument (); Doc.opendataregion ("Po_company"). SetValue ("A Beijing Company Limited"); Assigns a value to the data region, that is, the data is populated to the corresponding position in the template fmctrl.setsavefilepage (// Save PDF Action or Requestmapping method fmctrl.setwriter (DOC); Fmctrl.filldocumentaspdf ("Doc/template.doc", Documentopentype.word, "123.pdf"); // Populate Word templates and convert to PDF
Save the code for the action or Requestmapping method (/savepdf) of the PDF:
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)
[Original]java for Word to PDF