如何用纯java代码实现word转pdf
1:用apache pio 读取doc文件,然后转成html文件用Jsoup格式化html文件,最后用itext将html文件转成pdf。
2:使用jdoctopdf来实现,这是一个封装好的包,可以把doc转换成pdf,html,xml等格式,调用很方便。
3:地址http://www.maxstocker.com/jdoctopdf/downloads.php需要注意中文字体的写入问题。
4:使用jodconverter来调用openOffice的服务来转换,openOffice有个各个平台的版本,所以这种方法跟方法1一样都是跨平台的。
jodconverter的下载地址:http://www.artofsolving.com/opensource/jodconverter首先要安装openOffice,下载地址:office.org/download/index.html" target="_blank">http://www.openoffice.org/download/index.html5:安装完后要启动openOffice的服务,具体启动方法请自行google。
6:效果最好的一种方法,但是需要window环境,而且速度是最慢的需要安装msofficeWord以及SaveAsPDFandXPS.exe(word的一个插件,用来把word转化为pdf)7:Office版本是2007,因为SaveAsPDFandXPS是微软为office2007及以上版本开发的插件。
8:SaveAsPDFandXPS下载地址:microsoft.com/zh-cn/download/details.aspx?id=7" target="_blank">http://www.microsoft.com/zh-cn/download/details.aspx?id=7。
9:需要转换的工具 ,看你是linux还是word 。
word还好不需要安装。
linux就麻烦了。
爪哇是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java平台(即JavaEE, JavaME, JavaSE)的总称。
Java自面世后就非常流行,发展迅速,对C++语言形成了有力冲击。
Java技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于个人PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。
在全球云计算和移动互联网的产业环境下,Java更具备了显著优势和广阔前景。
如何用纯java代码实现word转pdf
用Java内嵌iText生成PDF文档需要5个步骤:①建立com.lowagie.text.Document对象的实例。
Document document = new Document();②建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中。
PDFWriter.getInstance(document, new FileOutputStream("Helloworld.PDF"));③打开文档。
document.open();④向文档中添加内容。
document.add(new Paragraph("Hello World"));⑤关闭文档。
document.close();通过上面的5个步骤,就能产生一个Helloworld.PDF的文件,文件内容为"Hello World"。
word转pdf格式的时候自制的图表变形,为什么?
在word转pdf后,图文变形的原因大多都是因为转换器造成的,可能使用的转换器本身并不支持图文格式的文件相互转换,解决问题的方法:使用专业的转换器,在选择转换器前,可以先了解他的功能是否具备图文格式的文件进行转换,转换器选好了操作就很简单了,以迅捷pdf转换器为例:1. 首先打开PDF转换器,选择需要转换的文档格式,这里我们直接单击选中“Word转PDF”;2. 然后单击界面上方的“添加文件/文件夹”按键,将需要进行转换的Word文件添加到软件中,一次可以上传多个,同时选出适合存放生成文档的保存路径;3. 路径设置成功后,直接按下“开始转换”按键,稍等一会就可以了。
下面这篇经验也是介绍图文格式的转换方法,可以参考一下http://jingyan.baidu.com/article/e6c8503c07e4cde54e1a1867.html
word文档转换成pdf 用java代码怎么实现
推荐下面免费的方法转成PDF试试:方法一:使用虚拟打印机pdf factory即可,而且其他格式文件只要是能够打印,选择这个虚拟打印机,都可以做成PDF文件,很简单实用;方法二:使用专门的转换软件,把文件转成PDF文件;方法三:用其他虚拟打印机转成PDF文件。
方法四:用WPS本身自带的转换功能转成PDF文件。
...
word转成pdf的图表怎么许虚线变成实线了
需要用到插件jacob,自己去下载吧。
import com.jacob.activeX.ActiveXComponent;import com.jacob.com.ComThread;import com.jacob.com.Dispatch;import com.jacob.com.Variant;public class D2P {private ActiveXComponent wordCom = null;private Object wordDoc = null;private final Variant False = new Variant(false);private final Variant True = new Variant(true);/** *//** *//** *//*** 打开word文档** @param filePath* word文档* @return 返回word文档对象*/public boolean openWord(String filePath) {//建立ActiveX部件wordCom = new ActiveXComponent("Word.Application");try {//返回wrdCom.Documents的DispatchDispatch wrdDocs = wordCom.getProperty("Documents").toDispatch();//调用wrdCom.Documents.Open方法打开指定的word文档,返回wordDocwordDoc = Dispatch.invoke(wrdDocs, "Open", Dispatch.Method,new Object[] { filePath }, new int[1]).toDispatch();return true;} catch (Exception ex) {ex.printStackTrace();}return false;}/** *//** *//** *//*** 关闭word文档*/public void closeWord() {//关闭word文件wordCom.invoke("Quit", new Variant[] {});}/** *//** *//** *//*** * 将word文档打印为PS文件后,使用Distiller将PS文件转换为PDF文件 *** @param sourceFilePath* 源文件路径 ** @param destinPSFilePath* 首先生成的PS文件路径 ** @param destinPDFFilePath* 生成PDF文件路径*/public void docToPDF(String sourceFilePath, String destinPSFilePath,String destinPDFFilePath) {if (!openWord(sourceFilePath)) {closeWord();return;}//建立Adobe Distiller的com对象ActiveXComponent distiller = new ActiveXComponent("PDFDistiller.PDFDistiller.1");try {//设置当前使用的打印机,我的Adobe Distiller打印机名字为"Adobe PDF"wordCom.setProperty("ActivePrinter", new Variant("MS Publisher Color Printer"));//设置printout的参数,将word文档打印为postscript文档。
目前只使用了前5个参数,如果要使用更多的话可以参考MSDN的office开发相关api//是否在后台运行Variant Background = False;//是否追加打印Variant Append = False;//打印所有文档int wdPrintAllDocument = 0;Variant Range = new Variant(wdPrintAllDocument);//输出的postscript文件的路径Variant OutputFileName = new Variant(destinPSFilePath);Dispatch.callN((Dispatch) wordDoc, "PrintOut", new Variant[] {Background, Append, Range, OutputFileName });System.out.println("由word文档打印为ps文档成功!");//调用Distiller对象的FileToPDF方法所用的参数,详细内容参考Distiller Api手册//作为输入的ps文档路径Variant inputPostScriptFilePath = new Variant(destinPSFilePath);//作为输出的pdf文档的路径Variant outputPDFFilePath = new Variant(destinPDFFilePath);//定义FileToPDF方法要使用adobe pdf设置文件的路径,在这里没有赋值表示并不使用pdf配置文件Variant PDFOption = new Variant("");//调用FileToPDF方法将ps文档转换为pdf文档Dispatch.callN(distiller, "FileToPDF", new Variant[] {inputPostScriptFilePath, outputPDFFilePath, PDFOption });System.out.println("由ps文档转换为pdf文档成功!");} catch (Exception ex) {ex.printStackTrace();} finally {closeWord();wordCom=null;//释放在程序线程中引用的其它com,比如Adobe PDFDistillerComThread.Release();}}public static void main(String[] argv) {D2P d2p = new D2P();d2p.docToPDF("d:/12.doc", "d:/1p.ps", "d:/1p.pdf");//这里是你建一个叫12.doc的word文档,生成的文档将在D盘下//1p.ps和1p.pdf(这是我们要的)}}
转载请注明出处51数据库 » java word转pdf 图表