回答
您可以使用Apache POI來閱讀doc文件,然後使用Apache PDFBox來編寫pdf文件。
轉換不是問題,但保持pdf格式與doc文件相同,並且還包含從doc文件到pdf的圖像/徽標。 –
您可以使用基於Open-Office的庫。 它允許從(和到)OpenOffice支持的所有格式轉換。
此外,如果您的文檔被OpenOffice正確讀取,它應該完全按照您看到的轉換。
我知道JOD Converter爲爲例:
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):
#!/bin/sh
DIR=$(pwd)
DOC=$DIR/$1
echo "Doc to convert : $DOC"
/user/bin/oowriter-invisible "macro://Standard.Module1.ConvertWordToPDF($DOC)"
您可以使用Aspose.Words for Java來convert Doc files to PDF。此組件在轉換爲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
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");
如果你提到'officetools'的來源,你的答案會更有價值。 – mkl
- 1. 更改Word文檔XML
- 2. 更改或Word文檔
- 3. 將pdf文件轉換爲word文檔
- 4. Word/PDF - 合併文檔
- 5. 打印Word文檔或PDF
- 6. 多個Word文檔到PDF轉換
- 7. 打印多個Word文檔到PDF
- 8. UIWebView和Word文檔更改格式
- 9. php生成word文檔更改頁面
- 10. 暫時保存Word文檔更改
- 11. Word文檔到mathml?
- 12. 得到word文檔
- 13. 在C#WinForms中預覽文檔(Word,Excel,PDF,文本文件等)?
- 14. 合併word文檔到單個文件
- 15. 創建Word文檔文件
- 16. LuaCOM Word文檔頭文件
- 17. MS Word文檔到RTF文檔
- 18. 帶Yii的PDF或Word創建文檔?
- 19. 保存嵌入Word文檔爲PDF
- 20. Word未能將文檔保存爲PDF
- 21. 將PDF轉換成Word文檔
- 22. Genexus 15,保存PDF,GIF,JPG,WORD文檔
- 23. PDF在Word文檔與VBA的片段?
- 24. 從word或pdf文檔創建報告
- 25. 將word文檔轉換爲pdf的vbscript
- 26. 將Word文檔轉換爲PDF - Python
- 27. 將word文檔轉換爲pdf
- 28. Razor查看Word文檔或PDF
- 29. 從模板Word文檔生成PDF
- 30. 將文檔從Word文檔複製到網頁時發生更改
發佈你已經有了將有助於代碼。 – Jeffrey
通過將Word文檔轉換爲PDF,您希望獲得什麼? –
也許通用兼容性! –