![](/img/trans.png)
[英]Ubuntu use JODconverter and openoffice convert doc to pdf
[英]Jodconverter : Can i use to convert HTML into PDF?
我有一個word文件。 我可以使用jodconverter轉換成pdf嗎? 我使用了從doc到pdf的jodconverter,它給出了很好的結果。 但是我不知道天氣支持從HTML到pdf。
謝謝!
從我對Jodconverter的了解中,我了解到它使用LibreOffice或OpenOffice將文檔文件導出為PDF。 現在,該軟件不能完全支持Microsoft Office。 僅Microsoft Office可以完全支持其格式,因此可以使用上述軟件之一來轉換您的docx文件,但在某些情況下(或在所有情況下)均會產生不愉快的結果。 據我了解,您有兩種選擇:
您可以使用LibreOffice軟件(或外部Java庫)將所有docx文檔轉換為LibreOffice,然后將它們導出為PDF,而不會出現兼容性問題。
您可以使用Microsoft Office Word進行從docx到pdf的轉換。 為了實現此目的,您將需要一個腳本來告訴MS Word進行轉換,並使用Runtime.getRuntime().exec(command);
從Java調用該腳本Runtime.getRuntime().exec(command);
。 至少那是我知道的方式,並且做到了。
這是我幾年前發現的腳本,在某些情況下仍然可以使用。 該腳本不是我的,所以我不能功勞。 您要做的就是創建一個擴展名為.vbs的新文件,並添加以下代碼。
Option Explicit
Doc2PDF Wscript.Arguments.Item(0)
Sub Doc2PDF( myFile )
Dim objDoc, objFile, objFSO, objWord, strFile, strPDF
Const wdFormatDocument = 0
Const wdFormatDocument97 = 0
Const wdFormatDocumentDefault = 16
Const wdFormatDOSText = 4
Const wdFormatDOSTextLineBreaks = 5
Const wdFormatEncodedText = 7
Const wdFormatFilteredHTML = 10
Const wdFormatFlatXML = 19
Const wdFormatFlatXMLMacroEnabled = 20
Const wdFormatFlatXMLTemplate = 21
Const wdFormatFlatXMLTemplateMacroEnabled = 22
Const wdFormatHTML = 8
Const wdFormatPDF = 17
Const wdFormatRTF = 6
Const wdFormatTemplate = 1
Const wdFormatTemplate97 = 1
Const wdFormatText = 2
Const wdFormatTextLineBreaks = 3
Const wdFormatUnicodeText = 7
Const wdFormatWebArchive = 9
Const wdFormatXML = 11
Const wdFormatXMLDocument = 12
Const wdFormatXMLDocumentMacroEnabled = 13
Const wdFormatXMLTemplate = 14
Const wdFormatXMLTemplateMacroEnabled = 15
Const wdFormatXPS = 18
Const wdFormatOfficeDocumentTemplate = 23
Const wdFormatMediaWiki = 24
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set objWord = CreateObject( "Word.Application" )
With objWord
.Visible = false
If objFSO.FileExists( myFile ) Then
Set objFile = objFSO.GetFile( myFile )
strFile = objFile.Path
Else
WScript.Echo "FILE OPEN ERROR: The file does not exist" & vbCrLf
.Quit
Exit Sub
End If
strPDF = objFSO.BuildPath( objFile.ParentFolder, _
objFSO.GetBaseName( objFile ) & ".pdf" )
.Documents.Open strFile
Set objDoc = .ActiveDocument
objDoc.SaveAs strPDF, wdFormatPDF
objDoc.Close
.Quit
End With
End Sub
這是一個可用於將docx文件導出為PDF的方法的小示例:
private void convertFile(String text) {
File f = new File(text);
if (f.exists() && f.getName().endsWith(".docx")) {
// The full path of your script, in my case is the Desktop.
String converterLocation = System.getProperty("user.home") + "\\Desktop\\wordToPdf.vbs";
// wscript <converterLocation> <"fullFilePath">
String command = "wscript " + converterLocation + " \"" + f.getAbsolutePath();
try {
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
}
我知道這個答案不是您期望的,但我只想指出我所知道的您的問題的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.