OpenOffice.org has a powerful support for plug-ins (called Macros) that allow a lot of additional functionality to be added to application. One common task is to convert MS/Word documents (.doc) into PDF. The recipe here uses Basic to program an OpenOffice.org macro to convert from DOC to PDF. We then illustrate how to turn this into a command line tool to convert from DOC to PDF. (This example was developed by DannyB.)
First, start up OpenOffice.org, perhaps as oowriter. Then, from the Tools menu, select Macros, Organize Macros, OpenOffice.org Basic. A window will popup. Navigate, in the Macro from area, to My Macros, Standard, Module1. Click on Edit to edit the Main module to include just the following code:
REM ***** BASIC ***** Sub ConvertWordToPDF(cFile) cURL = ConvertToURL(cFile) ' Open the document. ' Just blindly assume that the document is of a type that OOo will ' correctly recognize and open -- without specifying an import filter. oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, Array(MakePropertyValue("Hidden", True), )) Dim comps comps = split (cFile, ".") If UBound(comps) > 0 Then comps(UBound(comps)) = "pdf" cfile = join (comps, ".") Else cfile = cFile + ".pdf" Endif cURL = ConvertToURL(cFile) ' Save the document using a filter. oDoc.storeToURL(cURL, Array(MakePropertyValue("FilterName", "writer_pdf_Export"), )) oDoc.close(True) End Sub Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue Dim oPropertyValue As New com.sun.star.beans.PropertyValue If Not IsMissing( cName ) Then oPropertyValue.Name = cName EndIf If Not IsMissing( uValue ) Then oPropertyValue.Value = uValue EndIf MakePropertyValue() = oPropertyValue End Function |
Save and exit from OpenOffice.org.
Now create a shell script, perhaps called doc2pdf in /usr/local/bin with:
#!/bin/sh DIR=$(pwd) DOC=$DIR/$1 /usr/bin/oowriter -invisible "macro:///Standard.Module1.ConvertWordToPDF($DOC)" |
Then simply run it:
$ doc2pdf my.doc |
and you should end up with a my.pdf!
The script is nothing perfect, and there is an issue in that the script will return before OpenOffice.org has finished its work. Thus, to convert a whole directory of files, you may want sonething like:
$ for i in *.doc; do echo $i; doc2pdf "$i"; sleep 5; done |
The code to handle the newer xml based MS/Office file formats (or more specifically to handle the 4 character filename extensions like .xlsx, .docx, .pptx) was contributed by Victor Danilchenko. It replaced:
cFile = Left(cFile, Len(cFile) - 4) + ".pdf" |
with:
Dim comps comps = split (cFile, ".") If UBound(comps) > 0 Then comps(UBound(comps)) = "pdf" cfile = join (comps, ".") Else cfile = cFile + ".pdf" Endif |
Markus Dietsch offered a solution to the sleeping for 5 seconds above, due to the fact that oowriter detaches itself from the shell. His solution is to start oowriter and obtain the running process' name:
$ oowriter $ ps ax | grep openoffice 7378 pts/3 Sl 0:00 /usr/lib/openoffice/program/soffice.bin -writer -splash-pipe=5 |
Use this process command line with our start arguments:
/usr/lib/openoffice/program/soffice.bin -writer -invisible "macro:///Standard.Module1.ConvertWordToPDF($DOC)" |
This process does not detach itself from the shell and lives as long as the converting takes and is then coming back.
Transfer documents into excel with pdf converter software. This convert pdf to word product will save you so much time. Get the details of pdf file conversion toolsand how they were created. If you are using all Microsoft applications then you can buy software as well. Here you can get useful advice on purchasing new softwareand what to look for.
相关推荐
标题中的“word2007 word转PDF加载项”指的是一个特定的Microsoft Office 2007插件,它的功能是允许用户将Word文档转换成PDF格式。在没有这种加载项的情况下,用户可能需要借助其他第三方软件或在线工具来完成转换。...
程序主要功能是,打开word文档,将其转换成PDF文件保存。...程序是使用VS2012编写,运行环境要安装microsoft office2010或2013,msword.olb导入MFC的过程可以上网搜一下,很多博文都有详细介绍,再次就不赘述了。
内容概要:基于VBA开发带宏的Excel*.xlsb文件,打开这个Excel文件点击转换按钮,选择需要转换的文件既可将MS Word,Excel,PPT等文档转换为PDF的小软件。 适合人群:无需任何编程基础,只需要会基本操作Excel就可。...
但经调查,PDF的原文件为word,因此采用了比较偷懒的方式 把PDF转为word,再由word转为PDF PDF文件得以最大程度的压缩,并且保证了效果。 希望大家可以借鉴。 注:需要利用adobe专业版的组件PDFMakerAPI.dll 和 ...
在Linux环境下将Word文档转换为PDF时,可能会遇到中文字符显示不正常或出现“问号”(?)的问题。这通常是因为在转换过程中系统缺少支持中文的字体,导致无法正确渲染中文文字。以下是一些关于如何解决这个问题以及...
要将其他格式的文件(如HTML、Word文档或图片)转换为PDF,首先需要将这些文件解析成iTextSharp能理解的结构。例如,对于HTML,可以使用HTML Agility Pack解析HTML并将其转化为文本和图像,然后通过iTextSharp将它们...
迅捷pdf转换成word转换器是一款专业PDF转Word软件。软件功能强大、操作简单,用户只需把PDF文件拖拽到软件界面中,然后单击“转换”即可完成转换。使用本软件,可以很方便快捷地把pdf文档转换为word文档、txt文本、...
标题提到的"word/ppt转换pdf-pdf转换为jpg-jpg加水印"涵盖了四个主要操作:Word文档转PDF、PPT转换成PDF、PDF转为JPG图像,以及在JPG图片上添加水印。下面将详细解释这些知识点。 1. **Word文档转PDF**: 在不同的...
PDF转换成word转换器界面简单,功能稳定,并且保持原PDF文件布局转换成高质量的MS Word文件,准确地再现了PDF文件原有的文字,表格,列和图形等。 PDF转换成Word转换器是一个独立的程序 - 它完全不要Adobe Acrobat ...
在本文中,我们将深入探讨如何在Visual Studio 2015环境下使用Microsoft Office的API将Word文档转换为PDF文档。这个过程涉及到几个关键步骤,包括系统需求、API接口的使用以及C++编程技术。 首先,确保您的计算机上...
1、利用小美的Jacob调用MS Office转换文档为PDF 2、JCom是日本的一个开源项目,可以轻松实现office转换pdf 3、可以利用开源的OpenOffice,这个是linux提供的一个用于office的工具,调用内部API可以方便转换。 另外...
office文档转化为pdf文件 c++代码-office to pdf (包含WORD EXCEL POWPOINT) (office document into a pdf file c ++ code -office to pdf (containing WORD EXCEL POWPOINT))
本主题主要关注如何使用JAVA编程语言将常见的办公软件格式,如Word(.doc)、Excel(.xls)、PowerPoint(.ppt)以及图像文件(如.tif)转换为统一的PDF格式。PDF(Portable Document Format)因其跨平台兼容性和...
JODConverter则是一个工具,它可以将Office文档转换为其他格式,如PDF。通过使用OpenOffice或LibreOffice作为后端,JODConverter可以处理Word文档的转换任务,这在需要跨平台兼容或者需要预览、打印不同格式的场景中...
#import "C:\\Program Files\\Microsoft Office\\Office14\\MSWORD.OLB" rename_namespace("MSWord") \ auto_search \ auto_rename \ no_auto_exclude \ rename("ExitWindows", "WordExitWindows") #import "C...
总之,"word转pdf.zip" 提供的工具包是一个Java实现的Word到PDF转换解决方案,开发者需要理解如何使用Java API,处理字体映射,以及在代码中正确地调用转换功能。同时,注意在实际应用中解决可能出现的乱码问题,以...
AnyBizSoft PDF Converter是一款全面专业的PDF转换器,支持将PDF转换为Word(DOC/DOCX)、PowerPoint(PPT/PPTX)、HTML、TXT等格式,经测试对中文字符(简繁中文)支持良好,转换效果也不错,能够保存原有PDF的页面...
同时,pdf shaper 还采用了易于使用的界面与高DPI显示器兼容,除对PDF文档的处理外,还能够处理RTF和标准TXT文件,MS Word DOC和DOCX文档以及各种图像类型,绝对是您高效办公,提高工作效率必不可少的电脑软件。
"jacob_word转pdf类_" 指的是一种使用Jacob库来实现Java程序中Word到PDF转换的方法。Jacob(Java COM Bridge)是一个Java库,它允许Java应用程序调用COM组件,如Microsoft Office,以执行各种任务,包括文件格式的...