2011-08-16 25 views
0

.docファイルを.pdfに変換する方法はありますか?画像を含むことができるdocファイルと同じフォーマットを維持しますか?word docをpdfファイルに変更する

docからPDFファイルを生成できますが、テキストのみが表示されます。

+2

をPDFに変換しOpenOfficeのマクロを使用することができます。 – Jeffrey

+0

Word文書をPDFに変換して得たいものは何ですか? –

+0

多分普遍的な互換性! –

答えて

2

Apache POIを使用してdocファイルを読み込み、Apache PDFBoxを使用してpdfファイルを書き込むことができます。

+0

変換は問題ではありませんが、pdfのフォーマットをdocファイルと同じに保ち、docファイルからpdfへのimage/logoも含みます。 –

4

Open-Officeベースのライブラリを使用できます。 OpenOfficeでサポートされているすべての形式から変換することができます。

また、あなたのドキュメントがOpenOfficeによって正しく読み込まれている場合は、表示されているとおりに変換する必要があります。

私はJOD Converterためexemple知っている:あなたはまた、(OOインストールされている)単純なコマンドラインを使用することができます

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(); 

を:

#!/bin/sh 
DIR=$(pwd) 
DOC=$DIR/$1 
echo "Doc to convert : $DOC" 
/user/bin/oowriter-invisible "macro://Standard.Module1.ConvertWordToPDF($DOC)" 
0

あなたはconvert Doc files to PDFAspose.Words for Javaを使用することができます。このコンポーネントは、PDFに変換されたときに、文書の書式を保持します。また、テキストとともに画像を変換します。

開示:私はAsposeの開発者エバンジェリストとして働いています。

1

あなたは

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 
1
import officetools.OfficeFile; 

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

OfficeFile f = new OfficeFile(fis,"localhost","8100", false); 

、などのPDFとしてエクスポートするドキュメントのためにすでに役立つだろう持っているコードを投稿

f.convert(fos,"pdf"); 
+1

あなたが 'officetools'の起源について言及したならば、あなたの答えはより価値があるでしょう。 – mkl

関連する問題