Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将word文档更改为pdf文件_Java_Pdf_Doc - Fatal编程技术网

Java 将word文档更改为pdf文件

Java 将word文档更改为pdf文件,java,pdf,doc,Java,Pdf,Doc,有没有一种方法可以将.doc文件转换为.pdf文件,使其格式与可以包含图像的doc文件相同 我可以从文档生成PDF文件,但只显示文本。您可以使用读取文档文件,然后写入PDF文件 您可以使用基于Open Office的库。 它允许转换OpenOffice支持的所有格式 此外,如果OpenOffice正确读取了您的文档,则应完全按照您看到的方式对其进行转换 我知道的例子有: File inputFile = new File("document.doc"); File outputFile = ne

有没有一种方法可以将.doc文件转换为.pdf文件,使其格式与可以包含图像的doc文件相同


我可以从文档生成PDF文件,但只显示文本。

您可以使用读取文档文件,然后写入PDF文件

您可以使用基于Open Office的库。 它允许转换OpenOffice支持的所有格式

此外,如果OpenOffice正确读取了您的文档,则应完全按照您看到的方式对其进行转换

我知道的例子有:

File inputFile = new File("document.doc");
File outputFile = new File("document.pdf");

// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
connection.connect();

// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);

// close the connection
connection.disconnect();
还可以使用简单的命令行(安装了oo):

你可以用它。此组件在转换为PDF时保留word文档的格式。它还转换图像和文本


披露:我在Aspose担任开发人员宣传员。

您可以使用Openoffice宏将文档导出为pdf格式

sub Docaspdf  

rem ----------------------------------------------------------------------  
rem define variables  
dim document   as object  
dim dispatcher as object  

rem ----------------------------------------------------------------------  
rem get access to the document  
document   = ThisComponent.CurrentController.Frame  
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")  

rem ----------------------------------------------------------------------  
dim args1(2) as new com.sun.star.beans.PropertyValue  
args1(0).Name = "URL"  
args1(0).Value = "file:///C:/doc.pdf"  
args1(1).Name = "FilterName"  
args1(1).Value = "writer_pdf_Export"  
args1(2).Name = "FilterData"  
args1(2).Value = Array(Array("UseLosslessCompression",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Quality",0,90,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ReduceImageResolution",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("MaxImageResolution",0,300,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("UseTaggedPDF",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("SelectPdfVersion",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportNotes",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportBookmarks",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("OpenBookmarkLevels",0,-1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("UseTransitionEffects",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("IsSkipEmptyPages",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("IsAddStream",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EmbedStandardFonts",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("FormsType",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportFormFields",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("AllowDuplicateFieldNames",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerToolbar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerMenubar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerWindowControls",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ResizeWindowToInitialPage",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("CenterWindow",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("OpenInFullScreenMode",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("DisplayPDFDocumentTitle",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("InitialView",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Magnification",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Zoom",0,100,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PageLayout",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("FirstPageOnLeft",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("InitialPage",0,1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Printing",0,2,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Changes",0,4,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EnableCopyingOfContent",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EnableTextAccessForAccessibilityTools",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportLinksRelativeFsys",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PDFViewSelection",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ConvertOOoTargetToPDFTarget",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportBookmarksToPDFDestination",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("_OkButtonString",0,"",com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EncryptFile",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PreparedPasswords",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("RestrictPermissions",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PreparedPermissionPassword",0,Array(),com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE))  

dispatcher.executeDispatch(document, ".uno:ExportToPDF", "", 0, args1())  
end sub
转换为pdf

f.convert(fos,"pdf");

发布您已有的代码会有所帮助。您希望通过将Word文档转换为PDF获得什么?可能是通用兼容性!你的问题解决了吗?那么,你的问题解决了吗?接受一个答案;)转换不是问题,但是保持pdf格式与文档文件相同,并且还包括从文档文件到pdf的图像/徽标。如果您提到了
officetools
,您的答案将更有价值。
import officetools.OfficeFile; 

FileInputStream(new File("test.doc"));  
FileOutputStream fos = new FileOutputStream(new File("test.pdf")); /

OfficeFile f = new OfficeFile(fis,"localhost","8100", false);  
f.convert(fos,"pdf");